Class: Remap::Rule::Map
- Inherits:
-
Abstract
- Object
- Abstract
- Remap::Rule::Map
- Defined in:
- lib/remap/rule/map.rb,
lib/remap/rule/map/enum.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: Enum, Optional, Path, Required
Instance Method Summary collapse
- #add(&block) ⇒ self
-
#adjust(&block) ⇒ Map
(also: #then)
A post-processor method.
- #backtrace ⇒ Array<String>
-
#call(state) ⇒ 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
#add(&block) ⇒ self
173 174 175 |
# File 'lib/remap/rule/map.rb', line 173 def add(&block) tap { fn << block } end |
#adjust(&block) ⇒ Map Also known as: then
A post-processor method
59 60 61 62 63 |
# File 'lib/remap/rule/map.rb', line 59 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) ⇒ State
This method is abstract.
Represents a required or optional mapping rule
45 46 47 |
# File 'lib/remap/rule/map.rb', line 45 def call(state) raise NotImplementedError, "#{self.class}#call not implemented" end |
#enum(&block) ⇒ Map
An enumeration processor
107 108 109 110 111 112 113 114 115 |
# File 'lib/remap/rule/map.rb', line 107 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
136 137 138 139 140 141 142 |
# File 'lib/remap/rule/map.rb', line 136 def if(&block) add do |outer_state| outer_state.execute(&block).fmap do |bool, state| bool ? outer_state.value : state.ignore!("#if returned false") end end end |
#if_not(&block) ⇒ Map
164 165 166 167 168 169 170 |
# File 'lib/remap/rule/map.rb', line 164 def if_not(&block) add do |outer_state| outer_state.execute(&block).fmap do |bool, state| bool ? state.ignore!("#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
78 79 80 81 82 |
# File 'lib/remap/rule/map.rb', line 78 def pending(reason = "Pending mapping") add do |state| state.ignore!(reason) end end |
#rule ⇒ Rule
31 |
# File 'lib/remap/rule/map.rb', line 31 attribute? :rule, Rule.default { Void.call(EMPTY_HASH) } |