class Stannum::Contracts::Definition
Struct
that encapsulates a constraint definition on a contract.
Attributes
@!attribute [rw] constraint
@return [Stannum::Constraints::Base] the defined constraint.
@!attribute [rw] contract
@return [Stannum::Contracts::Base] the contract containing the constraint.
@!attribute [rw] options
@return [Hash<Symbol, Object>] the options defined for the constraint.
Public Class Methods
@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
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
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
@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
@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
@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