Sha256: d3e4315a49315a0ac003fc49c311c6ebb1f9a1e29c3bec540b88a00c6b55ffea

Contents?: true

Size: 992 Bytes

Versions: 5

Compression:

Stored size: 992 Bytes

Contents

require 'configatron'
require 'yaml'

module Rake::Funnel::Tasks::EnvironmentsSupport
  class Loader
    class << self
      def load_configuration(config, store = configatron)
        log("Configuring for #{config[:name]}")
        store.unlock!
        store.reset!

        store.env = config[:name]

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

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

        store.lock!

        log('')
        log(store.inspect)
      end

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

      private
      def log(message)
        Rake.rake_output_message(message)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rake-funnel-0.0.6.pre lib/rake/funnel/tasks/environments_support/loader.rb
rake-funnel-0.0.5.pre lib/rake/funnel/tasks/environments_support/loader.rb
rake-funnel-0.0.4.pre lib/rake/funnel/tasks/environments_support/loader.rb
rake-funnel-0.0.3.pre lib/rake/funnel/tasks/environments_support/loader.rb
rake-funnel-0.0.2.pre lib/rake/funnel/tasks/environments_support/loader.rb