Sha256: 72dcb79ce6a92f9f9442bb87196e71efc28ead61c977a400a58d2996eade7f97

Contents?: true

Size: 539 Bytes

Versions: 2

Compression:

Stored size: 539 Bytes

Contents

require 'active_model'

module ActiveModel

  module Validations

    class CreditCardValidator < ActiveModel::EachValidator

      def validate_each(record, attribute, value)
        unless CreditCardValidation::Validator.new(value).valid?
          record.errors[attribute] << (options[:message] || "is not a valid credit card")
        end
      end

    end

    module ClassMethods

      def validates_credit_card(*attributes)
        validates_with CreditCardValidator, _merge_attributes(*attributes)
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
credit_card_validation-1.0.0 lib/active_model/validations/credit_card_validator.rb
credit_card_validation-0.0.1 lib/active_model/validations/credit_card_validator.rb