Sha256: f0b9f2a667ebdcec52cf96a1d0b02aca4adcef85a86bf5279538f1bfc3386e80

Contents?: true

Size: 369 Bytes

Versions: 5

Compression:

Stored size: 369 Bytes

Contents

class CoordinateValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value.respond_to?(:latitude) &&
              (-90..90).cover?(value.latitude) &&
              value.respond_to?(:longitude) &&
              (-180..180).cover?(value.longitude)

    record.errors.add(attribute, options[:message] || :invalid)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mysql_point-1.0.4 lib/coordinate_validator.rb
mysql_point-1.0.3 lib/coordinate_validator.rb
mysql_point-1.0.2 lib/coordinate_validator.rb
mysql_point-1.0.1 lib/coordinate_validator.rb
mysql_point-1.0.0 lib/coordinate_validator.rb