Module: DataMapper::ValidationsExt
- Defined in:
- lib/ixtlan/datamapper/validations_ext.rb
Instance Method Summary collapse
- #_save(execute_hooks = true) ⇒ Object
-
#validate ⇒ Boolean
Run validations on the resource.
-
#validate_children ⇒ Object
Run validations on the associated child resources.
-
#validate_parents ⇒ Object
Run validations on the associated parent resources.
Instance Method Details
#_save(execute_hooks = true) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ixtlan/datamapper/validations_ext.rb', line 4 def _save(execute_hooks = true) result = super # TODO: should we wrap it with run_once? unless result validate if dirty_self? validate_parents if dirty_parents? validate_children if dirty_children? end result end |
#validate ⇒ Boolean
Run validations on the resource
23 24 25 |
# File 'lib/ixtlan/datamapper/validations_ext.rb', line 23 def validate valid? end |
#validate_children ⇒ Object
Run validations on the associated child resources
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ixtlan/datamapper/validations_ext.rb', line 44 def validate_children child_associations.each do |collection| if collection.dirty? collection.each do |child| unless child.valid? relationship_errors = (errors[collection.relationship.name] ||= []) unless relationship_errors.include?(child.errors) relationship_errors << child.errors end end end end end end |
#validate_parents ⇒ Object
Run validations on the associated parent resources
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ixtlan/datamapper/validations_ext.rb', line 30 def validate_parents parent_relationships.each do |relationship| parent = relationship.get(self) unless parent.valid? unless errors[relationship.name].include?(parent.errors) errors[relationship.name] = parent.errors end end end end |