Class: CoordinateValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/active_validation/validators/coordinate_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/active_validation/validators/coordinate_validator.rb', line 3

def validate_each(record, attribute, value)
  boundary = options.fetch(:boundary, :coordinate).to_sym
  unless BOUNDARIES.include?(boundary)
    raise ArgumentError,
      "Unknown boundary: #{boundary.inspect}. Valid boundaries are: #{BOUNDARIES.map(&:inspect).join(', '.freeze)}"
  end

  unless valid?(value, options)
    record.errors[attribute] << (options.fetch(:message, false) || I18n.t("active_validation.errors.messages.coordinate.#{boundary}"))
  end
end