Class: Validation::Rule::Field

Inherits:
StretchyRule show all
Defined in:
lib/validation/rule/field.rb

Instance Method Summary collapse

Methods inherited from StretchyRule

#empty_ok?, #initialize, #invalid_empty?, #is_empty?, #params, #required?

Constructor Details

This class inherits a constructor from Validation::Rule::StretchyRule

Instance Method Details

#error_keyObject



5
6
7
# File 'lib/validation/rule/field.rb', line 5

def error_key
  :field
end

#valid_class?(value) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/validation/rule/field.rb', line 18

def valid_class?(value)
  [String, Symbol, Numeric].any?{|c| value.is_a?(c) }
end

#valid_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/validation/rule/field.rb', line 9

def valid_value?(value)
  return true if empty_ok?(value)
  if params[:array]
    value.all? {|v| valid_class?(v) && !is_empty?(v) }
  else
    valid_class?(value) && !is_empty?(value)
  end
end