Class: Blacklight::OpenStructWithHashAccess

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/blacklight/utils.rb

Overview

An OpenStruct that responds to common Hash methods

Instance Method Summary collapse

Instance Method Details

#deep_dupObject



55
56
57
# File 'lib/blacklight/utils.rb', line 55

def deep_dup
  self.class.new @table.deep_dup
end

#merge(other_hash) ⇒ OpenStructWithHashAccess

Merge the values of this OpenStruct with another OpenStruct or Hash

Parameters:

  • other_hash (Hash, #to_h)

Returns:



43
44
45
# File 'lib/blacklight/utils.rb', line 43

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

#merge!(other_hash) ⇒ OpenStructWithHashAccess

Merge the values of another OpenStruct or Hash into this object

Parameters:

  • other_hash (Hash, #to_h)

Returns:



51
52
53
# File 'lib/blacklight/utils.rb', line 51

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

#select(*args, &block) ⇒ Object



26
27
28
# File 'lib/blacklight/utils.rb', line 26

def select *args, &block
  self.class.new to_h.select(*args, &block)
end

#sort_by(*args, &block) ⇒ Object



30
31
32
# File 'lib/blacklight/utils.rb', line 30

def sort_by *args, &block
  self.class.new Hash[to_h.sort_by(*args, &block)]
end

#sort_by!(*args, &block) ⇒ Object



34
35
36
37
# File 'lib/blacklight/utils.rb', line 34

def sort_by! *args, &block
  replace Hash[to_h.sort_by(*args, &block)]
  self
end

#to_hHash

Expose the internal hash

Returns:

  • (Hash)


22
23
24
# File 'lib/blacklight/utils.rb', line 22

def to_h
  @table
end