class SerializeHasMany::Validators::TypeValidator
Public Instance Methods
attr_name()
click to toggle source
# File lib/serialize_has_many/validators/type_validator.rb, line 6 def attr_name options[:attr_name] end
attributes()
click to toggle source
# File lib/serialize_has_many/validators/type_validator.rb, line 14 def attributes [ attr_name ] end
child_class()
click to toggle source
# File lib/serialize_has_many/validators/type_validator.rb, line 10 def child_class options[:child_class] end
validate(record)
click to toggle source
# File lib/serialize_has_many/validators/type_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/type_validator.rb, line 30 def validate_each(record, items) items.each do |item| unless item.nil? || item.kind_of?(child_class) record.errors.add "#{attr_name}", "item is not of type #{child_class}" end end end