Skip to content

Commit

Permalink
Blacklight::OpenStructWithHashAccess should expose a HashWithIndiffer…
Browse files Browse the repository at this point in the history
…entAccess
  • Loading branch information
cbeer committed Dec 3, 2016
1 parent 061ac75 commit a5437bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/blacklight/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def self.protected_attributes_enabled?
class OpenStructWithHashAccess < OpenStruct
delegate :keys, :each, :map, :has_key?, :key?, :include?, :empty?, :length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!, :replace, :fetch, :to_json, :as_json, to: :to_h

def initialize(*args)
super

@table = @table.with_indifferent_access
end

##
# Expose the internal hash
# @return [Hash]
Expand Down Expand Up @@ -55,6 +61,12 @@ def merge! other_hash
def deep_dup
self.class.new @table.deep_dup
end

protected

def convert_key(key)
key.is_a?(Symbol) ? key : key.to_sym
end
end

##
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/blacklight/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
end

it "exposes the internal hash table" do
expect(@h.to_h).to be_a_kind_of(Hash)
expect(@h.to_h).to be_a_kind_of(HashWithIndifferentAccess)
expect(@h.to_h[:a]).to eq 1
end

it "exposes keys" do
expect(@h.keys).to include(:a, :b)
end

end

describe "#key?" do
Expand Down

0 comments on commit a5437bb

Please sign in to comment.