Class: RangeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/simple_range_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attribObject (readonly)

Returns the value of attribute attrib.



5
6
7
# File 'lib/simple_range_validator.rb', line 5

def attrib
  @attrib
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



7
8
9
10
# File 'lib/simple_range_validator.rb', line 7

def validate_each(record, attribute, value)
  @attrib = attribute
  record.errors[attribute] << "must be within: #{show_range}" unless within? value
end