Module: Stannum::Entities::Constraints::ClassMethods
- Defined in:
- lib/stannum/entities/constraints.rb
Overview
Class methods to extend the class when including Constraints.
Instance Method Summary collapse
-
#constraint(attr_name = nil, constraint = nil, &block) ⇒ Object
Defines a constraint on the entity or one of its properties.
-
#contract ⇒ Stannum::Contract
The Contract object for the entity.
Instance Method Details
#constraint {|entity| ... } ⇒ Object #constraint(constraint) ⇒ Object #constraint(attr_name) {|value| ... } ⇒ Object #constraint(attr_name, constraint) ⇒ Object
Defines a constraint on the entity or one of its properties.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/stannum/entities/constraints.rb', line 79 def constraint(attr_name = nil, constraint = nil, &block) attr_name, constraint = resolve_constraint(attr_name, constraint) if block_given? constraint = Stannum::Constraint.new(&block) else validate_constraint(constraint) end contract.add_constraint(constraint, property: attr_name) end |
#contract ⇒ Stannum::Contract
Returns The Contract object for the entity.
92 93 94 |
# File 'lib/stannum/entities/constraints.rb', line 92 def contract self::Contract end |