class SerializeHasMany::Validators::NestedValidator
Public Instance Methods
attr_name()
click to toggle source
# File lib/serialize_has_many/validators/nested_validator.rb, line 6 def attr_name options[:attr_name] end
attributes()
click to toggle source
# File lib/serialize_has_many/validators/nested_validator.rb, line 14 def attributes [ attr_name ] end
child_class()
click to toggle source
# File lib/serialize_has_many/validators/nested_validator.rb, line 10 def child_class options[:child_class] end
validate(record)
click to toggle source
# File lib/serialize_has_many/validators/nested_validator.rb, line 18 def validate(record) items = record.send attr_name if items.nil? nil elsif items.kind_of?(Array) validate_each(record, items) else record.errors.add "#{attr_name}", "is not an array" end end
validate_each(record, items)
click to toggle source
# File lib/serialize_has_many/validators/nested_validator.rb, line 30 def validate_each(record, items) items.each do |item| if !item.nil? && !item.valid? item.errors.each do |error, message| record.errors.add "#{attr_name}.#{error}", message end end end end