Sha256: bec318127adb35bbaff249b9fb72d1d3bf0d795340ce670585d2713975bd8bac

Contents?: true

Size: 537 Bytes

Versions: 4

Compression:

Stored size: 537 Bytes

Contents

require 'ostruct'
module Blacklight
  class OpenStructWithHashAccess < OpenStruct
    delegate :keys, :reject!, :select!, :include, :fetch, :to => :to_h

    def []=(key, value)
      send "#{key}=", value
    end

    def [](key)
      send key
    end

    def to_h
      @table
    end

    def merge other_hash
      self.class.new to_h.merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
    end

    def merge! other_hash
      @table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
    end 
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-4.9.0 lib/blacklight/utils.rb
blacklight-4.8.0 lib/blacklight/utils.rb
blacklight-4.7.0 lib/blacklight/utils.rb
blacklight-4.7.0.pre1 lib/blacklight/utils.rb