Sha256: 683ed9adaf382b298aead9a1ae268402209fcb30cac9b0116daecd1fe8912c61

Contents?: true

Size: 652 Bytes

Versions: 2

Compression:

Stored size: 652 Bytes

Contents

# Uses the Phony.plausible method to validate an attribute.
# Usage:
#   validate :phone_number, :phony_plausible => true
class PhonyPlausibleValidator < ActiveModel::EachValidator

  # Validates a String using Phony.plausible? method.
  def validate_each(record, attribute, value)
    return if value.blank?
    record.errors[attribute] << (options[:message] || "is an invalid number") if not Phony.plausible?(value)
  end

end

module ActiveModel
  module Validations
    module HelperMethods

      def validates_plausible_phone(*attr_names)
        validates_with PhonyPlausibleValidator, _merge_attributes(attr_names)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phony_rails-0.1.6 lib/validators/phony_validator.rb
phony_rails-0.1.5 lib/validators/phony_validator.rb