Class: Eaternet::ValidatedObject Abstract
- Inherits:
-
Object
- Object
- Eaternet::ValidatedObject
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/eaternet/validated_object.rb
Overview
This class is abstract.
Subclass and add attr_accessor
and validations
to create custom validating objects.
Uses ActiveModel::Validations to create self-validating Plain Old Ruby objects. This is especially useful when importing data from one system into another.
Direct Known Subclasses
Lives_1_0::Business, Lives_1_0::FeedInfo, Lives_1_0::Inspection, Lives_1_0::Legend, Lives_1_0::Violation
Defined Under Namespace
Classes: TypeValidator
Instance Method Summary collapse
-
#check_validations! ⇒ Object
Run any validations and raise an error if invalid.
-
#initialize {|new_object| ... } ⇒ ValidatedObject
constructor
Instantiate and validate a new object.
Constructor Details
#initialize {|new_object| ... } ⇒ ValidatedObject
Instantiate and validate a new object.
50 51 52 53 |
# File 'lib/eaternet/validated_object.rb', line 50 def initialize(&block) block.call(self) check_validations! end |
Instance Method Details
#check_validations! ⇒ Object
Run any validations and raise an error if invalid.
57 58 59 |
# File 'lib/eaternet/validated_object.rb', line 57 def check_validations! fail ArgumentError, errors..join('; ') if invalid? end |