Sha256: ca16204b6065bd8b7904e6a6eece55c325fc5a0b8c5f96d2fe716804c13b9823

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

require 'configatron'
require 'yaml'

module Rake::Funnel::Support::Environments
  class Loader
    class << self
      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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rake-funnel-0.3.2.pre lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.3.1.pre lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.3.0.pre lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.2.0.pre lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.1.0.pre lib/rake/funnel/support/environments/loader.rb