class Stannum::Contracts::Definition

Struct that encapsulates a constraint definition on a contract.

Attributes

constraint[RW]

@!attribute [rw] constraint

@return [Stannum::Constraints::Base] the defined constraint.
contract[RW]

@!attribute [rw] contract

@return [Stannum::Contracts::Base] the contract containing the
  constraint.
options[RW]

@!attribute [rw] options

@return [Hash<Symbol, Object>] the options defined for the constraint.

Public Class Methods

new(attributes = {}) click to toggle source

@param attributes [Hash] The attributes for the definition. @option attributes [Stannum::Constraints::Base] :constraint The constraint

to define for the contract.

@option attributes [Stannum::Contracts::Base] :contract The contract for

which the constraint is defined.

@option attributes [Hash<Symbol, Object>] :options The options for the

constraint.
# File lib/stannum/contracts/definition.rb, line 15
def initialize(attributes = {})
  attributes.each do |key, value|
    send(:"#{key}=", value)
  end
end

Public Instance Methods

==(other) click to toggle source

Compares the other object with the definition.

@param other [Object] The object to compare.

@return [Boolean] true if the other object is a Definition with the same

attributes; otherwise false.
# File lib/stannum/contracts/definition.rb, line 40
def ==(other)
  other.is_a?(self.class) &&
    other.constraint == constraint &&
    other.contract.equal?(contract) &&
    other.options == options
end
concatenatable?() click to toggle source

Indicates whether the defined constraint is inherited via concatenation.

@return [Boolean] true if options is set to a truthy

value; otherwise false.
# File lib/stannum/contracts/definition.rb, line 51
def concatenatable?
  !!options.fetch(:concatenatable, true)
end
property() click to toggle source

@return [nil, String, Symbol, Array<String, Symbol>] the property scope of

the constraint.
# File lib/stannum/contracts/definition.rb, line 57
def property
  options[:property]
end
property_name() click to toggle source

@return [nil, String, Symbol, Array<String, Symbol>] the property name of

the constraint, used for generating errors. If not given, defaults to
the value of #property.
# File lib/stannum/contracts/definition.rb, line 64
def property_name
  options.fetch(:property_name, options[:property])
end
sanity?() click to toggle source

@return [Boolean] true if options is set to a truthy value;

otherwise false.
# File lib/stannum/contracts/definition.rb, line 70
def sanity?
  !!options[:sanity]
end