Class: Remap::Selector::Key

Inherits:
Unit
  • Object
show all
Defined in:
lib/remap/selector/key.rb

Instance Method Summary collapse

Instance Method Details

#call(state, &block) ⇒ State<T>

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/remap/selector/key.rb', line 19

def call(state, &block)
  unless block
    return call(state, &:itself)
  end

  state.bind(key: key) do |hash, inner_state, &error|
    requirement[hash] do
      return error["Expected a hash"]
    end

    value = hash.fetch(key) do
      return error["Key [#{key}] not found"]
    end

    block[inner_state.set(value, key: key)]
  end
end