Sha256: 2f054c2a9a62c5a9ee2e2507c98d0aedc0f37479b810464e60b55315fa3c06af

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

require 'yaml'

module OpsPreflight
  class Config
    CONFIG_FILE = 'config/preflight.yml'

    def initialize
      config
    end

    def client_args(rails_env)
      str = ''
      config.each do |var, value|
        next if var == :environments

        str << " #{var.to_s.upcase}='#{value}'"
      end

      if config[:environments] && config[:environments][rails_env.to_sym]
        config[:environments][rails_env.to_sym].each do |var, value|
          str << " #{var.to_s.upcase}='#{value}'"
        end
      end

      str
    end

    protected
    def config
      @config ||= begin
        new_config = YAML::load(ERB.new(File.read(CONFIG_FILE)).result)

        symbolize_keys!(new_config)
        symbolize_keys!(new_config[:environments])

        new_config[:environments].each do |env, hash|
          symbolize_keys!(hash)
        end

        new_config.freeze
      end
    end

    def symbolize_keys!(hash)
      hash.keys.each do |key|
        hash[(key.to_sym rescue key) || key] = hash.delete(key)
      end
      hash
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ops_preflight-1.3.1 lib/ops_preflight/config.rb
ops_preflight-1.3.0 lib/ops_preflight/config.rb
ops_preflight-1.2.1 lib/ops_preflight/config.rb
ops_preflight-1.2.0 lib/ops_preflight/config.rb
ops_preflight-1.1.2 lib/ops_preflight/config.rb
ops_preflight-1.1.1 lib/ops_preflight/config.rb
ops_preflight-1.1.0 lib/ops_preflight/config.rb
ops_preflight-1.0.0.pre2 lib/ops_preflight/config.rb
ops_preflight-1.0.0.pre1 lib/ops_preflight/config.rb