Class: Stannum::Contracts::Definition
- Inherits:
-
Object
- Object
- Stannum::Contracts::Definition
- Defined in:
- lib/stannum/contracts/definition.rb
Overview
Struct that encapsulates a constraint definition on a contract.
Instance Attribute Summary collapse
-
#constraint ⇒ Stannum::Constraints::Base
The defined constraint.
-
#contract ⇒ Stannum::Contracts::Base
The contract containing the constraint.
-
#options ⇒ Hash<Symbol, Object>
The options defined for the constraint.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the other object with the definition.
-
#concatenatable? ⇒ Boolean
Indicates whether the defined constraint is inherited via concatenation.
-
#initialize(attributes = {}) ⇒ Definition
constructor
A new instance of Definition.
-
#property ⇒ nil, ...
The property scope of the constraint.
-
#property_name ⇒ nil, ...
The property name of the constraint, used for generating errors.
-
#sanity? ⇒ Boolean
True if options is set to a truthy value; otherwise false.
Constructor Details
#initialize(attributes = {}) ⇒ Definition
Returns a new instance of Definition.
15 16 17 18 19 |
# File 'lib/stannum/contracts/definition.rb', line 15 def initialize(attributes = {}) attributes.each do |key, value| send(:"#{key}=", value) end end |
Instance Attribute Details
#constraint ⇒ Stannum::Constraints::Base
Returns the defined constraint.
23 24 25 |
# File 'lib/stannum/contracts/definition.rb', line 23 def constraint @constraint end |
#contract ⇒ Stannum::Contracts::Base
Returns the contract containing the constraint.
28 29 30 |
# File 'lib/stannum/contracts/definition.rb', line 28 def contract @contract end |
#options ⇒ Hash<Symbol, Object>
Returns the options defined for the constraint.
32 33 34 |
# File 'lib/stannum/contracts/definition.rb', line 32 def @options end |
Instance Method Details
#==(other) ⇒ Boolean
Compares the other object with the definition.
40 41 42 43 44 45 |
# File 'lib/stannum/contracts/definition.rb', line 40 def ==(other) other.is_a?(self.class) && other.constraint == constraint && other.contract.equal?(contract) && other. == end |
#concatenatable? ⇒ Boolean
Indicates whether the defined constraint is inherited via concatenation.
51 52 53 |
# File 'lib/stannum/contracts/definition.rb', line 51 def concatenatable? !!.fetch(:concatenatable, true) end |
#property ⇒ nil, ...
Returns the property scope of the constraint.
57 58 59 |
# File 'lib/stannum/contracts/definition.rb', line 57 def property [:property] end |
#property_name ⇒ nil, ...
Returns the property name of the constraint, used for generating errors. If not given, defaults to the value of #property.
64 65 66 |
# File 'lib/stannum/contracts/definition.rb', line 64 def property_name .fetch(:property_name, [:property]) end |
#sanity? ⇒ Boolean
Returns true if options is set to a truthy value; otherwise false.
70 71 72 |
# File 'lib/stannum/contracts/definition.rb', line 70 def sanity? !![:sanity] end |