Sha256: 3899cdfa2523095632c0dc171b552a43d55174d7d04ad0665965f98702ca147f

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'configatron'
require 'yaml'

module Rake
  module Funnel
    module Support
      module Environments
        class Loader
          class << self
            def load_configuration(config, store = configatron, customizer = nil)
              $stderr.print("Configuring for #{config[:name]}\n")
              store.unlock!
              store.reset!

              store.env = config[:name]
              load(config, store)

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

              store.lock!

              $stderr.print("\n" + store.inspect + "\n")
            end

            private

            def load(config, store)
              operation = 'Loading'
              config.fetch(:config_files, []).each do |file|
                $stderr.print("#{operation} #{file}\n")
                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

3 entries across 3 versions & 1 rubygems

Version Path
rake-funnel-0.24.0 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.23.0 lib/rake/funnel/support/environments/loader.rb
rake-funnel-0.22.3 lib/rake/funnel/support/environments/loader.rb