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) ⇒ 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.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stannum/entities/constraints.rb', line 80 def constraint(attr_name = nil, constraint = nil, &) attr_name, constraint = resolve_constraint(attr_name, constraint) if block_given? constraint = Stannum::Constraint.new(&) else validate_constraint(constraint) end contract.add_constraint(constraint, property: attr_name) end |
#contract ⇒ Stannum::Contract
Returns The Contract object for the entity.
93 94 95 |
# File 'lib/stannum/entities/constraints.rb', line 93 def contract self::Contract end |