Sha256: 1b35c15f4eaf61b64967fc612ca1037e94a222a5476d45375476f5a44a1b5581

Contents?: true

Size: 729 Bytes

Versions: 5

Compression:

Stored size: 729 Bytes

Contents

require 'yaml'
Configliere.use :define
module Configliere
  #
  # EnvVar -- load configuration from environment variables
  #
  module EnvVar
    def env_vars *envs
      envs.each do |env|
        case env
        when Hash
          env.each do |env_param, env_var|
            adopt_env_var! env_param, env_var
          end
        else
          param = env.to_s.downcase.to_sym
          adopt_env_var! param, env
        end
      end
    end
    
  protected
    def adopt_env_var! param, env
      env   = env.to_s
      param_definitions[param][:env_var] ||= env
      val = ENV[env]
      self[param] = val if val
    end
  end

  Param.class_eval do
    # include read / save operations
    include EnvVar
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
configliere-0.3.4 lib/configliere/env_var.rb
configliere-0.3.3 lib/configliere/env_var.rb
configliere-0.3.2 lib/configliere/env_var.rb
configliere-0.3.1 lib/configliere/env_var.rb
configliere-0.3.0 lib/configliere/env_var.rb