Class: Mack::Assets::Helpers

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mack/assets/asset_helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#asset_hosts(source = '') ⇒ Object

Return the asset hosts for this application.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mack/assets/asset_helpers.rb', line 37

def asset_hosts(source = '')
  ret_val = ''

  # if no explicit asset_host setting, then use the one defined in configatron (if exists)
  host = @hosts || (configatron.mack.assets.hosts.nil? ? '' : configatron.mack.assets.hosts)

  if host.kind_of?(Proc)
    ret_val = host.call(source)
  else
    ret_val = sprintf(host, rand(max_distribution))
  end
  return ret_val
end

#asset_hosts=(host) ⇒ Object

Set the asset hosts for this app. It supports the following format:

  • plain string: the string literal will be considered as the asset hosts (e.g. ‘assets.foo.com’)

  • formatted string: to support asset host distribution (e.g. ‘asset%d.foo.com’)

  • a proc object: to support custom asset hosts generation (e.g. Proc.new { |source| ‘assets.foo.com’ }

The max number of distribution can be set from configatron.mack.assets.max_distribution. The default value is 4



23
24
25
# File 'lib/mack/assets/asset_helpers.rb', line 23

def asset_hosts=(host)
  @hosts = host
end

#max_distributionObject

Return the max number of asset hosts distribution



30
31
32
# File 'lib/mack/assets/asset_helpers.rb', line 30

def max_distribution
  return configatron.mack.assets.max_distribution
end

#reset!Object

Clear previously set configuration for asset hosts



54
55
56
# File 'lib/mack/assets/asset_helpers.rb', line 54

def reset!
  @hosts = nil
end