class Interactor::Contracts::Breach
A wrapper for breached contract terms that encapsulates the failed property and its messages.
Attributes
messages[R]
The messages describing the breach
@example
breach = Interactor::Contracts::Breach.new(:name, ["name is missing"]) breach.messages #=> ["name is missing"]
@api public @return [Array<String>] the messages describing the breach
property[R]
The property violated in the contract
@example
breach = Interactor::Contracts::Breach.new(:name, ["name is missing"]) breach.property #=> :name
@api public @return [Symbol] the property violated in the contract
Public Class Methods
new(property, messages)
click to toggle source
Represents a breach of a contract with its messages
@example
Interactor::Contracts::Breach.new(:name, ["name is missing"])
@api semipublic @param [Symbol] property the property violated in the contract @param [Array<String>] messages the messages describing the breach.
# File lib/interactor/contracts/breach.rb, line 16 def initialize(property, messages) @property = property @messages = messages end
Public Instance Methods
to_ary()
click to toggle source
Allows the Breach
to be splatted out as arguments to a block
@api private @return [Array<Symbol, Array<String>>]
# File lib/interactor/contracts/breach.rb, line 45 def to_ary [property, messages] end
to_h()
click to toggle source
Converts the Breach
to an equivalent Hash
@example
breach = Interactor::Contracts::Breach.new(:name, ["name is missing"]) breach.to_h #=> {:name => ["name is missing"]}
@api public @return [Hash]
# File lib/interactor/contracts/breach.rb, line 57 def to_h { property => messages } end