Class: Remap::Selector::Key
- Inherits:
-
Unit
- Object
- Unit
- Remap::Selector::Key
- Defined in:
- lib/remap/selector/key.rb
Overview
Selects value at key from state
Instance Method Summary collapse
-
#call(state) {|| ... } ⇒ State<U>
Selects #key from state and passes it to block.
-
#key ⇒ #hash
#hash.
Instance Method Details
#call(state) {|| ... } ⇒ State<U>
Selects #key from state and passes it to block
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/remap/selector/key.rb', line 28 def call(state, &block) unless block raise ArgumentError, "The key selector requires an iteration block" end hash = state.fetch(:value) { return state } unless hash.is_a?(Hash) state.fatal!("Expected hash got %s", hash.class) end value = hash.fetch(key) do state.ignore!("Key [%s] (%s) not found", key, key.class) end state.set(value, key: key).then(&block) end |
#key ⇒ #hash
Returns #hash.
18 |
# File 'lib/remap/selector/key.rb', line 18 attribute :key, Types::Key |