class ClearLogic::Matcher
Constants
- CASES
Public Class Methods
call(*args) { |on| ... }
click to toggle source
# File lib/clear_logic/matcher.rb, line 7 def self.call(*args) new.matcher.call(*args) { |on| yield(on) } end
Public Instance Methods
matcher()
click to toggle source
# File lib/clear_logic/matcher.rb, line 11 def matcher dry_cases = CASES.each_with_object({}) do |one_case, case_list| case_list[one_case] = send("#{one_case}_case") end Dry::Matcher.new(dry_cases) end
Private Instance Methods
case_patterns(result, patterns)
click to toggle source
# File lib/clear_logic/matcher.rb, line 35 def case_patterns(result, patterns) patterns.any? do |pattern| return false unless respond_to?("#{pattern}_pattern", private: true) send("#{pattern}_pattern", result) end end
failure_case()
click to toggle source
# File lib/clear_logic/matcher.rb, line 28 def failure_case Dry::Matcher::Case.new( match: ->(result, *patterns) { patterns.any? ? case_patterns(result, patterns) : result.failure? }, resolve: ->(result) { result } ) end
success_case()
click to toggle source
# File lib/clear_logic/matcher.rb, line 21 def success_case Dry::Matcher::Case.new( match: ->(result) { result.success? }, resolve: ->(result) { result } ) end