Class: ActiveSet::Instructions

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Instructions

Returns a new instance of Instructions.



9
10
11
12
# File 'lib/active_set/instructions/base.rb', line 9

def initialize(hash)
  @hash = hash
  @flattened_hash = hash.flatten_keys.transform_keys { |k| k.map(&:to_s) }
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



7
8
9
# File 'lib/active_set/instructions/base.rb', line 7

def hash
  @hash
end

Instance Method Details

#get(keypath) ⇒ Object



24
25
26
# File 'lib/active_set/instructions/base.rb', line 24

def get(keypath)
  @hash.dig(*keypath)
end

#process_adapter(set:, adapter:) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/active_set/instructions/base.rb', line 14

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