lib/plumb/match_class.rb in plumb-0.0.3 vs lib/plumb/match_class.rb in plumb-0.0.4

- old
+ new

@@ -1,20 +1,21 @@ # frozen_string_literal: true -require 'plumb/steppable' +require 'plumb/composable' module Plumb class MatchClass - include Steppable + include Composable - attr_reader :matcher + attr_reader :children def initialize(matcher = Undefined, error: nil, label: nil) raise TypeError '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 def call(result) @matcher === result.value ? result : result.invalid(errors: @error)