Sha256: ca1c85748d541d1568239721209482ec094e474bfc0cf8facd18dda960f3a222

Contents?: true

Size: 451 Bytes

Versions: 11

Compression:

Stored size: 451 Bytes

Contents

require 'hashie'

class Musterb::HashExtractor
  attr_reader :parent, :value

  def initialize(value, parent)    
    @value = to_string_access(value)
    @parent = parent
  end

  def [](symbol)
    if @value.has_key? symbol
      @value[symbol]
    else
      @parent[symbol]
    end
  end

  private
  def to_string_access(hash)
    hash.dup.tap do |hash|
      hash.extend Hashie::HashExtensions
      hash.hashie_stringify_keys!
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
musterb-1.0.1 lib/musterb/hash_extractor.rb
musterb-0.2.0 lib/musterb/hash_extractor.rb
musterb-0.1.2 lib/musterb/hash_extractor.rb
musterb-0.1.1 lib/musterb/hash_extractor.rb
musterb-0.1.0 lib/musterb/hash_extractor.rb
musterb-0.0.7 lib/musterb/hash_extractor.rb
musterb-0.0.6 lib/musterb/hash_extractor.rb
musterb-0.0.5 lib/musterb/hash_extractor.rb
musterb-0.0.4 lib/musterb/hash_extractor.rb
musterb-0.0.3 lib/musterb/hash_extractor.rb
musterb-0.0.2 lib/musterb/hash_extractor.rb