Class: Plumb::MatchClass
- Inherits:
-
Object
- Object
- Plumb::MatchClass
- Includes:
- Composable
- Defined in:
- lib/plumb/match_class.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #call(result) ⇒ Object
-
#initialize(matcher = Undefined, error: nil, label: nil) ⇒ MatchClass
constructor
A new instance of MatchClass.
Methods included from Composable
#>>, #[], #as_node, #build, #check, #defer, #generate, included, #invalid, #invoke, #match, #metadata, #not, #pipeline, #policy, #static, #to_json_schema, #to_s, #transform, #value, wrap, #|
Methods included from Callable
Constructor Details
#initialize(matcher = Undefined, error: nil, label: nil) ⇒ MatchClass
Returns a new instance of MatchClass.
11 12 13 14 15 16 17 18 19 |
# File 'lib/plumb/match_class.rb', line 11 def initialize(matcher = Undefined, error: nil, label: nil) raise ParseError 'matcher must respond to #===' unless matcher.respond_to?(:===) @matcher = matcher @error = error.nil? ? build_error(matcher) : (error % matcher) @label = matcher.is_a?(Class) ? matcher.inspect : "Match(#{label || @matcher.inspect})" @children = [matcher].freeze freeze end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/plumb/match_class.rb', line 9 def children @children end |
Instance Method Details
#call(result) ⇒ Object
21 22 23 |
# File 'lib/plumb/match_class.rb', line 21 def call(result) @matcher === result.value ? result : result.invalid(errors: @error) end |