Sha256: 9401ff38c7e5bc08d8963cd3a9743a0e29efde78c2a9a04da728e08011a0a2b1

Contents?: true

Size: 644 Bytes

Versions: 20

Compression:

Stored size: 644 Bytes

Contents

class Hashr < Hash
  module EnvDefaults
    attr_writer :env_namespace

    def env_namespace=(env_namespace)
      @env_namespace = [env_namespace.upcase]
    end

    def env_namespace
      @env_namespace ||= []
    end

    def definition
      deep_enverize(super)
    end

    protected

      def deep_enverize(hash, nesting = env_namespace)
        hash.each do |key, value|
          nesting << key.to_s.upcase
          hash[key] = case value
          when Hash
            deep_enverize(value, nesting)
          else
            ENV.fetch(nesting.join('_'), value)
          end.tap { nesting.pop }
        end
      end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hashr-1.0.0 lib/hashr/env_defaults.rb
hashr-0.0.22 lib/hashr/env_defaults.rb
hashr-0.0.21 lib/hashr/env_defaults.rb
hashr-0.0.20 lib/hashr/env_defaults.rb
hashr-0.0.19 lib/hashr/env_defaults.rb
hashr-0.0.18 lib/hashr/env_defaults.rb
hashr-0.0.17 lib/hashr/env_defaults.rb
hashr-0.0.16 lib/hashr/env_defaults.rb
hashr-0.0.15 lib/hashr/env_defaults.rb
hashr-0.0.14 lib/hashr/env_defaults.rb
hashr-0.0.13 lib/hashr/env_defaults.rb
hashr-0.0.12 lib/hashr/env_defaults.rb
hashr-0.0.11 lib/hashr/env_defaults.rb
hashr-0.0.10 lib/hashr/env_defaults.rb
hashr-0.0.9 lib/hashr/env_defaults.rb
hashr-0.0.8 lib/hashr/env_defaults.rb
hashr-0.0.7 lib/hashr/env_defaults.rb
hashr-0.0.6 lib/hashr/env_defaults.rb
hashr-0.0.5 lib/hashr/env_defaults.rb
hashr-0.0.4 lib/hashr/env_defaults.rb