Class: Rulix::ActiveRecordValidator
- Inherits:
-
Object
- Object
- Rulix::ActiveRecordValidator
- Defined in:
- lib/rulix/active_record_validator.rb
Instance Attribute Summary collapse
-
#ruleset ⇒ Object
Returns the value of attribute ruleset.
Instance Method Summary collapse
-
#initialize(*args) ⇒ ActiveRecordValidator
constructor
A new instance of ActiveRecordValidator.
- #reduce_errors_into(record, error_hash) ⇒ Object
- #validate(record) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ActiveRecordValidator
Returns a new instance of ActiveRecordValidator.
5 6 7 8 9 |
# File 'lib/rulix/active_record_validator.rb', line 5 def initialize *args ruleset = args.first[:ruleset] self.ruleset = ruleset end |
Instance Attribute Details
#ruleset ⇒ Object
Returns the value of attribute ruleset.
3 4 5 |
# File 'lib/rulix/active_record_validator.rb', line 3 def ruleset @ruleset end |
Instance Method Details
#reduce_errors_into(record, error_hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rulix/active_record_validator.rb', line 23 def reduce_errors_into record, error_hash error_hash.reduce(record) do |subject, error| key, val = error if val.is_a? Hash reduce_errors_into record.send(key), val else val.flatten.map do |err| subject.errors.add key, err end end subject end end |