Class: Interactor::Contracts::Breach

Inherits:
Object
  • Object
show all
Defined in:
lib/interactor/contracts/breach.rb

Overview

A wrapper for breached contract terms that encapsulates the failed property and its messages.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, messages) ⇒ Breach

Represents a breach of a contract with its messages

Examples:

Interactor::Contracts::Breach.new(:name, ["name is missing"])

Parameters:

  • property (Symbol)

    the property violated in the contract

  • messages (Array<String>)

    the messages describing the breach.



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

def initialize(property, messages)
  @property = property
  @messages = messages
end

Instance Attribute Details

#messagesArray<String> (readonly)

The messages describing the breach

Examples:

breach = Interactor::Contracts::Breach.new(:name, ["name is missing"])
breach.messages  #=> ["name is missing"]

Returns:

  • (Array<String>)

    the messages describing the breach



27
28
29
# File 'lib/interactor/contracts/breach.rb', line 27

def messages
  @messages
end

#propertySymbol (readonly)

The property violated in the contract

Examples:

breach = Interactor::Contracts::Breach.new(:name, ["name is missing"])
breach.property  #=> :name

Returns:

  • (Symbol)

    the property violated in the contract



37
38
39
# File 'lib/interactor/contracts/breach.rb', line 37

def property
  @property
end

Instance Method Details

#to_aryArray<Symbol, Array<String>>

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.

Allows the Breach to be splatted out as arguments to a block

Returns:

  • (Array<Symbol, Array<String>>)


43
44
45
# File 'lib/interactor/contracts/breach.rb', line 43

def to_ary
  [property, messages]
end

#to_hHash

Converts the Breach to an equivalent Hash

Examples:

breach = Interactor::Contracts::Breach.new(:name, ["name is missing"])
breach.to_h  #=> {:name => ["name is missing"]}

Returns:

  • (Hash)


55
56
57
# File 'lib/interactor/contracts/breach.rb', line 55

def to_h
  {property => messages}
end