Module: ClassX::AttributeMethods::ClassMethods::ValidateEach

Defined in:
lib/classx/attribute.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#validate?(val) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/classx/attribute.rb', line 119

def validate? val
  return false unless val.respond_to? :all?

  if self.value_class
    return false unless val.kind_of?(self.value_class)

    case val
    when Hash
      if config[:validate_each].arity == 2
        val.all? {|item| config[:validate_each].call(*item) }
      else
        ClassX::Validate.validate(val, &config[:validate_each])
      end
    else
      val.all? {|item| config[:validate_each].call(*item) }
    end
  else
    val.all? {|item| config[:validate_each].call(*item) }
  end
end