Class: Lookbook::ConfigLoader
- Defined in:
- lib/lookbook/services/config_loader.rb
Instance Attribute Summary collapse
- #env ⇒ Object readonly
- #file ⇒ Object readonly
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(path, env: Rails.env) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
Methods inherited from Service
Constructor Details
#initialize(path, env: Rails.env) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
5 6 7 8 |
# File 'lib/lookbook/services/config_loader.rb', line 5 def initialize(path, env: Rails.env) @file = Engine.root.join(path) @env = env.to_sym end |
Instance Attribute Details
#env ⇒ Object (readonly)
3 4 5 |
# File 'lib/lookbook/services/config_loader.rb', line 3 def env @env end |
#file ⇒ Object (readonly)
3 4 5 |
# File 'lib/lookbook/services/config_loader.rb', line 3 def file @file end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/lookbook/services/config_loader.rb', line 10 def call if file.exist? config = YAML.load_file(file).deep_symbolize_keys env_config = config[:shared].to_h.deep_merge(config[env].to_h) Store.new(env_config) else raise ConfigError.new("Could not load configuration. No such file - #{file}") end end |