Class: Interactor::Contracts::Outcome

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/interactor/contracts/outcome.rb

Overview

The outcome of a Terms enforcement.

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Outcome

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiantes a new Outcome based on the results of a Terms enforcement

Parameters:

  • result (Dry::Validation::Result)

15
16
17
# File 'lib/interactor/contracts/outcome.rb', line 15

def initialize(result)
  @result = result
end

Instance Method Details

#breachesArray<Breach>

The list of breaches of the Terms

Examples:

terms = Interactor::Contract::Terms.new
terms.add do
  required(:name).filled
end

outcome = terms.call(:name => "Bilbo Baggins")
outcome.breaches  #=> []

Returns:

  • (Array<Breach>)

    the breaches of the Terms' constraints


48
49
50
51
52
# File 'lib/interactor/contracts/outcome.rb', line 48

def breaches
  BreachSet.new(result.messages(:full => true).map do |property, messages|
    Breach.new(property, messages)
  end)
end

#failure?Boolean

Checks whether the the Terms enforcement was a failure

Examples:

terms = Interactor::Contract::Terms.new
terms.add do
  required(:name).filled
end

outcome = terms.call(:name => "Bilbo Baggins")
outcome.failure?  #=> false.

Returns:

  • (Boolean)

67
68
69
# File 'lib/interactor/contracts/outcome.rb', line 67

def failure?
  !success?
end

#success?Boolean

Checks whether the the terms enforcement was a success

Examples:

terms = Interactor::Contract::Terms.new
terms.add do
  required(:name).filled
end

outcome = terms.call(:name => "Bilbo Baggins")
outcome.success?  #=> true

Returns:

  • (Boolean)

33
# File 'lib/interactor/contracts/outcome.rb', line 33

def_delegator :@result, :success?