Class: Rake::Funnel::Support::Environments::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/funnel/support/environments/loader.rb

Class Method Summary collapse

Class Method Details

.evaluate_erb(yaml, filename) ⇒ Object



36
37
38
39
40
# File 'lib/rake/funnel/support/environments/loader.rb', line 36

def evaluate_erb(yaml, filename)
  render = ERB.new(yaml)
  render.filename = filename
  render.result
end

.load_configuration(config, store = configatron, customizer = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rake/funnel/support/environments/loader.rb', line 10

def load_configuration(config, store = configatron, customizer = nil)
  Rake.rake_output_message("Configuring for #{config[:name]}")
  store.unlock!
  store.reset!

  store.env = config[:name]

  operation = 'Loading'
  config.fetch(:config_files, []).each do |file|
    Rake.rake_output_message("#{operation} #{file}")
    operation = 'Merging'

    yaml = File.read(file)
    yaml = evaluate_erb(yaml, file)
    yaml = YAML.load(yaml) || {}
    store.configure_from_hash(yaml)
  end

  customizer.call(store) if customizer && customizer.respond_to?(:call)

  store.lock!

  Rake.rake_output_message('')
  Rake.rake_output_message(store.inspect)
end