Class: Grape::Attack::Options::ProcOrNumberValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/grape/attack/options.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



12
13
14
15
16
17
# File 'lib/grape/attack/options.rb', line 12

def validate_each(record, attribute, value)
  return true if value.is_a?(Numeric)
  return true if value.is_a?(Proc) && value.call.is_a?(Numeric)

  record.errors.add attribute, "must be either a proc resolving in a numeric or a numeric"
end