Sha256: ee70c2e820777fb37585ffbb715a9d48b90d444fd299ff158a94d8d46a957ce6

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 KB

Contents

require 'active_model'
require 'active_validators/one_nine_shims/one_nine_string'

module ActiveValidators
  def self.activevalidators
    %w(email url respond_to phone slug ip credit_card date password twitter postal_code tracking_number siren ssn sin nino barcode date hex_color regexp)
  end

  # Require each validator independently or just pass :all
  #
  # call-seq:
  #   ActiveValidators.activate(:phone, :email, :date)
  #   ActiveValidators.activate(:all)
  def self.activate(*validators)
    syms = validators.include?(:all) ? activevalidators : validators.map(&:to_s) & activevalidators

    syms.each do |validator_name|
      require "active_validators/active_model/validations/#{validator_name}_validator"
    end
  end

  # Defines methods like validates_credit_card
  def define_helper_method_for_validator(validator)
    define_method('validates_'+validator) do |*fields|
      options ||= (fields.delete fields.find { |f| f.kind_of? Hash}) || true
      args = fields.push({ validator => options })
      validates(*args)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
activevalidators-6.0.0 lib/activevalidators.rb
activevalidators-5.1.0 lib/activevalidators.rb
activevalidators-5.0.1 lib/activevalidators.rb
activevalidators-5.0.0 lib/activevalidators.rb
activevalidators-4.1.0 lib/activevalidators.rb
activevalidators-4.0.3 lib/activevalidators.rb
activevalidators-4.0.2 lib/activevalidators.rb
activevalidators-4.0.1 lib/activevalidators.rb
activevalidators-4.0.0 lib/activevalidators.rb
activevalidators-3.3.0 lib/activevalidators.rb
activevalidators-3.2.0 lib/activevalidators.rb