Class: Wardrobe::Plugins::Validation::Validator
- Inherits:
-
Object
- Object
- Wardrobe::Plugins::Validation::Validator
- Defined in:
- lib/wardrobe/plugins/validation/validator.rb
Instance Attribute Summary collapse
-
#atr ⇒ Object
readonly
Returns the value of attribute atr.
-
#error_store ⇒ Object
readonly
Returns the value of attribute error_store.
-
#validation ⇒ Object
readonly
Returns the value of attribute validation.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, atr, error_store, validation = nil) ⇒ Validator
constructor
A new instance of Validator.
- #run(report = true) ⇒ Object
Constructor Details
#initialize(value, atr, error_store, validation = nil) ⇒ Validator
Returns a new instance of Validator.
10 11 12 13 14 15 |
# File 'lib/wardrobe/plugins/validation/validator.rb', line 10 def initialize(value, atr, error_store, validation = nil) @value = value @atr = atr @error_store = error_store @validation = validation || atr.[:validates] end |
Instance Attribute Details
#atr ⇒ Object (readonly)
Returns the value of attribute atr.
8 9 10 |
# File 'lib/wardrobe/plugins/validation/validator.rb', line 8 def atr @atr end |
#error_store ⇒ Object (readonly)
Returns the value of attribute error_store.
8 9 10 |
# File 'lib/wardrobe/plugins/validation/validator.rb', line 8 def error_store @error_store end |
#validation ⇒ Object (readonly)
Returns the value of attribute validation.
8 9 10 |
# File 'lib/wardrobe/plugins/validation/validator.rb', line 8 def validation @validation end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/wardrobe/plugins/validation/validator.rb', line 8 def value @value end |
Instance Method Details
#run(report = true) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wardrobe/plugins/validation/validator.rb', line 17 def run(report = true) if validation validate(validation, report) elsif value.respond_to?(:_validate!) if value._validation_errors.any? error_store.store[atr.name] = value._validation_errors end else Wardrobe.logger.warn("Unable to validate #{value.class} class") end end |