Class: AssetHostSelection::AssetProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/asset_host_selection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AssetProvider

Returns a new instance of AssetProvider.



20
21
22
23
24
25
# File 'lib/asset_host_selection.rb', line 20

def initialize(options = {})
  @domain    = options.fetch(:domain)
  @subdomain = options.fetch(:subdomain)
  @enabled   = options[:enabled]
  @cdn       = options[:cdn]
end

Instance Attribute Details

#cdnObject

Returns the value of attribute cdn.



5
6
7
# File 'lib/asset_host_selection.rb', line 5

def cdn
  @cdn
end

#enabledObject

Returns the value of attribute enabled.



5
6
7
# File 'lib/asset_host_selection.rb', line 5

def enabled
  @enabled
end

Class Method Details

.build_all(attributes = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/asset_host_selection.rb', line 7

def self.build_all(attributes = {})
  providers = {}
  settings_to_provider = {}
  settings_to_provider.compare_by_identity
  attributes.each do |key, settings|
    providers[key.to_sym] = settings_to_provider.fetch(settings) do
      settings_to_provider[settings] = new(settings)
    end
  end

  providers
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/asset_host_selection.rb', line 31

def enabled?
  return false if @cdn && cdn_disabled?
  @enabled != false
end

#hostObject



27
28
29
# File 'lib/asset_host_selection.rb', line 27

def host
  @host ||= [ @subdomain, @domain ].join(".")
end