Class: DomainSwitcher::ConfigLoader
- Inherits:
-
Object
- Object
- DomainSwitcher::ConfigLoader
- Defined in:
- lib/domain_switcher/config_loader.rb
Instance Attribute Summary collapse
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
-
#websites ⇒ Object
readonly
Returns the value of attribute websites.
Instance Method Summary collapse
-
#[](website_symbol) ⇒ Object
Retrieve a website by symbol.
- #default_domain ⇒ Object
- #default_website ⇒ Object
-
#initialize(config_file = 'config/websites.yml', env = 'development') ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
Constructor Details
#initialize(config_file = 'config/websites.yml', env = 'development') ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
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
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
7 8 9 |
# File 'lib/domain_switcher/config_loader.rb', line 7 def domains @domains end |
#websites ⇒ Object (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_domain ⇒ Object
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_website ⇒ Object
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 |