Module: Lab42::DataClass::Proxy::Constraints
- Included in:
- Lab42::DataClass::Proxy
- Defined in:
- lib/lab42/data_class/proxy/constraints.rb,
lib/lab42/data_class/proxy/constraints/maker.rb
Defined Under Namespace
Modules: Maker
Instance Method Summary collapse
- #check_constraints_against_defaults(constraints) ⇒ Object
- #define_constraint ⇒ Object
- #define_constraints(constraints) ⇒ Object
Instance Method Details
#check_constraints_against_defaults(constraints) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/lab42/data_class/proxy/constraints.rb', line 8 def check_constraints_against_defaults(constraints) errors = constraints .map(&_check_constraint_against_default) .compact raise ConstraintError, errors.join("\n\n") unless errors.empty? end |
#define_constraint ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lab42/data_class/proxy/constraints.rb', line 15 def define_constraint ->((attr, constraint)) do if members!.member?(attr) constraints[attr] << Maker.make_constraint(constraint) nil else attr end end end |
#define_constraints(constraints) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/lab42/data_class/proxy/constraints.rb', line 26 def define_constraints(constraints) errors = constraints.map(&define_constraint).compact unless errors.empty? raise UndefinedAttributeError, "constraints cannot be defined for undefined attributes #{errors.inspect}" end check_constraints_against_defaults(constraints) end |