Class: Hybag::Validator
- Inherits:
-
Object
- Object
- Hybag::Validator
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/hybag/validator.rb
Instance Attribute Summary collapse
-
#bag ⇒ Object
readonly
Returns the value of attribute bag.
Instance Method Summary collapse
- #bag_valid ⇒ Object
-
#initialize(bag) ⇒ Validator
constructor
A new instance of Validator.
- #require_persisted ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(bag) ⇒ Validator
Returns a new instance of Validator.
8 9 10 |
# File 'lib/hybag/validator.rb', line 8 def initialize(bag) @bag = bag end |
Instance Attribute Details
#bag ⇒ Object (readonly)
Returns the value of attribute bag.
6 7 8 |
# File 'lib/hybag/validator.rb', line 6 def bag @bag end |
Instance Method Details
#bag_valid ⇒ Object
18 19 20 |
# File 'lib/hybag/validator.rb', line 18 def bag_valid errors.add(:bag, "is not valid for bagging.") unless bag.baggable? end |
#require_persisted ⇒ Object
22 23 24 |
# File 'lib/hybag/validator.rb', line 22 def require_persisted errors.add(:bag, "is not persisted.") unless bag.persisted? end |
#validate! ⇒ Object
12 13 14 15 16 |
# File 'lib/hybag/validator.rb', line 12 def validate! unless self.valid? raise "Invalid Object for bagging" end end |