Class: Blacksheep::Decorators::ResultMatcher

Inherits:
ActionDecorator
  • Object
show all
Defined in:
lib/blacksheep/decorators/result_matcher.rb

Constant Summary collapse

Matcher =
-> {
  # Match `action_result` with status :ok for success
  success_case = Dry::Matcher::Case.new do |action_result, _|
    if action_result.success?
      action_result
    else
      # this is a constant from dry/core/constants
      Dry::Matcher::Undefined
    end
  end

  # Match `action_result` with status not :ok` for failure - other status' can be distinguished
  failure_case = Dry::Matcher::Case.new do |action_result, patterns|
    if !action_result.success! && (patterns.empty? || patterns.include?(action_result.status))
      value
    else
      Dry::Matcher::Undefined
    end
  end

  # Build the matcher
  Dry::Matcher.new(success: success_case, failure: failure_case)
}.call

Instance Method Summary collapse

Methods inherited from ActionDecorator

#__class__, #class, #decorators_chain

Instance Method Details

#callObject



33
34
35
# File 'lib/blacksheep/decorators/result_matcher.rb', line 33

def call(*)
  super
end

#performObject

Raises:



37
38
39
# File 'lib/blacksheep/decorators/result_matcher.rb', line 37

def perform(*)
  raise Blacksheep::Error, 'ResultMatcher does not support #perform'
end