Class: Dinamo::Model::Validation::EachValidator
- Defined in:
- lib/dinamo/model/validator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(attributes: [], **options) ⇒ EachValidator
constructor
A new instance of EachValidator.
- #validate(record) ⇒ Object
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(attributes: [], **options) ⇒ EachValidator
Returns a new instance of EachValidator.
22 23 24 25 26 |
# File 'lib/dinamo/model/validator.rb', line 22 def initialize(attributes: [], **) @attributes = attributes raise ArgumentError, ":attributes cannot be blank" if @attributes.empty? super end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
20 21 22 |
# File 'lib/dinamo/model/validator.rb', line 20 def attributes @attributes end |
Instance Method Details
#validate(record) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/dinamo/model/validator.rb', line 28 def validate(record) attributes.each do |key, val| value = record[key] next if (value.nil? && [:allow_nil]) || (value.blank? && [:allow_blank]) validate_each(record, key, value) end end |
#validate_each(record, attribute, value) ⇒ Object
37 38 39 |
# File 'lib/dinamo/model/validator.rb', line 37 def validate_each(record, attribute, value) raise NotImplementedError end |