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.



16
17
18
19
# File 'lib/interactor/contracts/breach.rb', line 16

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



29
30
31
# File 'lib/interactor/contracts/breach.rb', line 29

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



39
40
41
# File 'lib/interactor/contracts/breach.rb', line 39

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>>)


45
46
47
# File 'lib/interactor/contracts/breach.rb', line 45

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)


57
58
59
# File 'lib/interactor/contracts/breach.rb', line 57

def to_h
  { property => messages }
end