Class: Remap::Rule::Map
- Inherits:
-
Abstract
- Object
- Abstract
- Remap::Rule::Map
- Defined in:
- lib/remap/rule/map.rb,
lib/remap/rule/map/optional.rb,
lib/remap/rule/map/required.rb
Overview
Maps an input path to an output path
Defined Under Namespace
Classes: Optional, Path, Required
Instance Method Summary collapse
-
#adjust(&block) ⇒ Map
(also: #then)
A post-processor method.
- #backtrace ⇒ Array<String>
-
#call(state, &error) ⇒ State
abstract
Represents a required or optional mapping rule.
-
#enum(&block) ⇒ Map
An enumeration processor.
-
#if(&block) ⇒ Map
Keeps map, only if block is true.
- #if_not(&block) ⇒ Map
- #path ⇒ Hash
-
#pending(reason = "Pending mapping") ⇒ Map
A pending rule.
- #rule ⇒ Rule
Instance Method Details
#adjust(&block) ⇒ Map Also known as: then
A post-processor method
71 72 73 74 75 |
# File 'lib/remap/rule/map.rb', line 71 def adjust(&block) add do |state| state.execute(&block) end end |
#backtrace ⇒ Array<String>
34 |
# File 'lib/remap/rule/map.rb', line 34 attribute? :backtrace, Types::Backtrace, default: EMPTY_ARRAY |
#call(state, &error) ⇒ State
This method is abstract.
Represents a required or optional mapping rule
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/remap/rule/map.rb', line 45 def call(state, &error) unless error raise ArgumentError, "Map#call(state, &error) requires error handler block" end notice = catch :fatal do return path.input.call(state) do |inner_state| rule.call(inner_state) do |failure| return error[failure] end.then(&callback) end.then(&path.output) end raise notice.traced(backtrace).exception end |
#enum(&block) ⇒ Map
An enumeration processor
119 120 121 122 123 124 125 126 127 |
# File 'lib/remap/rule/map.rb', line 119 def enum(&block) add do |outer_state| outer_state.fmap do |id, state| Enum.call(&block).get(id) do state.ignore!("Enum value %p (%s) not defined", id, id.class) end end end end |
#if(&block) ⇒ Map
Keeps map, only if block is true
148 149 150 151 152 153 154 |
# File 'lib/remap/rule/map.rb', line 148 def if(&block) add do |outer_state| outer_state.execute(&block).fmap do |bool, state| bool ? outer_state.value : state.notice!("#if returned false") end end end |
#if_not(&block) ⇒ Map
176 177 178 179 180 181 182 |
# File 'lib/remap/rule/map.rb', line 176 def if_not(&block) add do |outer_state| outer_state.execute(&block).fmap do |bool, state| bool ? state.notice!("#if_not returned false") : outer_state.value end end end |
#path ⇒ Hash
28 |
# File 'lib/remap/rule/map.rb', line 28 attribute? :path, Path.default { Path.call(EMPTY_HASH) } |
#pending(reason = "Pending mapping") ⇒ Map
A pending rule
90 91 92 93 94 |
# File 'lib/remap/rule/map.rb', line 90 def pending(reason = "Pending mapping") add do |state| state.notice!(reason) end end |