Class: ActiveSet::Instructions
- Inherits:
-
Object
- Object
- ActiveSet::Instructions
- Defined in:
- lib/active_set/instructions/base.rb,
lib/active_set/instructions/entry.rb,
lib/active_set/instructions/entry/value.rb,
lib/active_set/instructions/entry/keypath.rb
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #get(keypath) ⇒ Object
-
#initialize(hash) ⇒ Instructions
constructor
A new instance of Instructions.
- #process_adapter(set:, adapter:) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Instructions
Returns a new instance of Instructions.
12 13 14 15 |
# File 'lib/active_set/instructions/base.rb', line 12 def initialize(hash) @hash = hash.with_indifferent_access @flattened_hash = hash.flatten_keys.transform_keys { |k| k.map(&:to_s) } end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'lib/active_set/instructions/base.rb', line 10 def hash @hash end |
Instance Method Details
#get(keypath) ⇒ Object
27 28 29 |
# File 'lib/active_set/instructions/base.rb', line 27 def get(keypath) @hash.dig(*keypath) end |
#process_adapter(set:, adapter:) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/active_set/instructions/base.rb', line 17 def process_adapter(set:, adapter:) @flattened_hash.reduce(set) do |inner_set, (keypath, value)| instruction = Entry.new(keypath, value) output = adapter.new(inner_set, instruction).process remove_from_instruction_set(key: instruction.path) if output[:processed] output[:set] end end |