Class: Lookbook::ConfigLoader

Inherits:
Service
  • Object
show all
Defined in:
lib/lookbook/services/config_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Service

call

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

#envObject (readonly)



3
4
5
# File 'lib/lookbook/services/config_loader.rb', line 3

def env
  @env
end

#fileObject (readonly)



3
4
5
# File 'lib/lookbook/services/config_loader.rb', line 3

def file
  @file
end

Instance Method Details

#callObject



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