Sha256: fe013ebcb1990ba3a65d782d0301223a8fe8d552b4d51c237c4ffc18ecaf40b1

Contents?: true

Size: 746 Bytes

Versions: 4

Compression:

Stored size: 746 Bytes

Contents

module A9n
  class Hash
    class << self
      def deep_prepare(hash, scope)
        hash.inject({}) do |result, (key, value)|
          key_name = key.respond_to?(:to_sym) ? key.to_sym : key
          result[key_name] = get_value(key, value, scope)
          result
        end
      end

      def merge(*items)
        return nil if items.compact.empty?

        items.compact.inject({}) { |sum, item| sum.merge!(item) }
      end

      private

      def get_value(key, value, scope)
        if value.is_a?(::Hash)
          deep_prepare(value, scope)
        elsif value.is_a?(Symbol) && value == :env
          A9n.env_var(scope.env_key_name(key), strict: A9n.strict?)
        else
          value
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
a9n-0.8.3 lib/a9n/ext/hash.rb
a9n-0.8.2 lib/a9n/ext/hash.rb
a9n-0.8.0 lib/a9n/ext/hash.rb
a9n-0.7.0 lib/a9n/ext/hash.rb