Class: Trailblazer::Context::Store::IndifferentAccess

Inherits:
Hash
  • Object
show all
Includes:
Hashie::Extensions::IndifferentAccess
Defined in:
lib/trailblazer/context/store/indifferent_access.rb

Overview

Simple yet indifferently accessible hash store, used as replica in Context::Container. It maintains cache for multiple hashes (wrapped_options, mutable_options etc).

Instance Method Summary collapse

Constructor Details

#initialize(hashes) ⇒ IndifferentAccess

Returns a new instance of IndifferentAccess.



11
12
13
14
15
16
17
# File 'lib/trailblazer/context/store/indifferent_access.rb', line 11

def initialize(hashes)
  hashes.each do |hash|
    hash.each do |key, value|
      self[key] = value
    end
  end
end

Instance Method Details

#convert_key(key) ⇒ Object

Override of Hashie::Extensions::IndifferentAccess#convert_key to store keys as Symbol by default instead of String. Why ? We need to pass ‘ctx` as keyword arguments most of the time.



29
30
31
32
# File 'lib/trailblazer/context/store/indifferent_access.rb', line 29

def convert_key(key)
  return key if Symbol === key 
  String === key ? key.to_sym : key
end

#indifferent_value(value) ⇒ Object

Override of Hashie::Extensions::IndifferentAccess#indifferent_value to not do deep indifferent access conversion. DISCUSS: Should we make this configurable ?



22
23
24
# File 'lib/trailblazer/context/store/indifferent_access.rb', line 22

def indifferent_value(value)
  value
end