Sha256: 2cf67754f22b877949c78ec8ff5bef7ab0f7071d3ea335bee5281d6025ba346a

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

require 'configatron'
require 'yaml'

module Rake
  module Funnel
    module Support
      module 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]
              load(config, store)

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

              store.lock!

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

            private

            def load(config, store)
              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) || {} # rubocop:disable Security/YAMLLoad
                store.configure_from_hash(yaml)
              end
            end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rake-funnel-0.22.1 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.22.0 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.21.2 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.21.1 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.21.0 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.20.2 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.20.1 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.20.0 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.19.0 lib/rake/funnel/support/environments/loader.rb