Sha256: a9afd395854682b8101769b05bec9f50b1b58b5472b301c8aa7d52e984901491

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'universal_validators_rails/version'
require 'universal_validators'
require 'active_record'

class DateValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    validator = ::UniversalValidators::DateValidator.new(value)
    record.errors.add(attribute, @options[:message] || 'Invalid date format') unless validator.valid?
  end
end

class DateTimeValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    validator = ::UniversalValidators::DateTimeValidator.new(value)
    record.errors.add(attribute, @options[:message] || 'Invalid date time format') unless validator.valid?
  end
end

class IpAddressValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    validator = ::UniversalValidators::IpValidator.new(value, @options[:with_mask] || false)
    record.errors.add(attribute, @options[:message] || 'Invalid ip address format') unless validator.valid?
  end
end

class MacAddressValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    validator = ::UniversalValidators::MacAddressValidator.new(value)
    record.errors.add(attribute, @options[:message] || 'Invalid mac address format') unless validator.valid?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
universal_validators_rails-1.0.0 lib/universal_validators_rails.rb