Class: DomainSwitcher::ConfigLoader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = 'config/websites.yml', env = 'development') ⇒ ConfigLoader

Returns a new instance of ConfigLoader.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/domain_switcher/config_loader.rb', line 9

def initialize(config_file = 'config/websites.yml', env = 'development')
  begin
    @conf = YAML::load_file(config_file)
  rescue ArgumentError => e
    raise ArgumentError.new("DomainSwitcher: Malformed config file (#{config_file}): #{e}")
  end
  raise ArgumentError.new("DomainSwitcher: Empty config file (#{config_file})") if !@conf or @conf.size == 0

  @env = env
  @websites = []
  @domains = []
  @websites_hash = {}
  parse_conf!
end

Instance Attribute Details

#domainsObject (readonly)

Returns the value of attribute domains.



7
8
9
# File 'lib/domain_switcher/config_loader.rb', line 7

def domains
  @domains
end

#websitesObject (readonly)

Returns the value of attribute websites.



6
7
8
# File 'lib/domain_switcher/config_loader.rb', line 6

def websites
  @websites
end

Instance Method Details

#[](website_symbol) ⇒ Object

Retrieve a website by symbol



64
65
66
# File 'lib/domain_switcher/config_loader.rb', line 64

def [](website_symbol)
  @websites_hash[website_symbol]
end

#default_domainObject



59
60
61
# File 'lib/domain_switcher/config_loader.rb', line 59

def default_domain
  @default_domain ||= @domains.find { |d| d.default? } || @domains.first
end

#default_websiteObject



55
56
57
# File 'lib/domain_switcher/config_loader.rb', line 55

def default_website
  @default_website ||= @websites.find { |w| w.default? } || @websites.first
end