Sha256: daf09a535f74cf59a578e47bfa67c2ef82ae9acf11be62c4fdc2199d8c2dba8e

Contents?: true

Size: 1.16 KB

Versions: 35

Compression:

Stored size: 1.16 KB

Contents

require 'active_model'
require 'active_support/concern'
require 'active_support/core_ext/array/wrap'
require 'polyblock/validators/polyblock_presence_validator'

module Polyblock
  module Validators
    extend ActiveSupport::Concern

    included do
      extend  HelperMethods
      include HelperMethods
    end

    module ClassMethods
      def validates_polyblock(*attributes)
        options = attributes.extract_options!.dup

        Polyblock::Validators.constants.each do |constant|
          if constant.to_s =~ /\APolyblock(.+)Validator\Z/
            validator_kind = $1.underscore.to_sym

            if options.has_key?(validator_kind)
              validator_options = options.delete(validator_kind)
              validator_options = {} if validator_options == true
              conditional_options = options.slice(:if, :unless)
              Array.wrap(validator_options).each do |local_options|
                method_name = Polyblock::Validators.const_get(constant.to_s).helper_method_name
                send(method_name, attributes, local_options.merge(conditional_options))
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
polyblock-0.9.7 lib/polyblock/validators.rb
polyblock-0.9.6 lib/polyblock/validators.rb
polyblock-0.9.5 lib/polyblock/validators.rb
polyblock-0.9.4 lib/polyblock/validators.rb
polyblock-0.9.3 lib/polyblock/validators.rb
polyblock-0.9.2 lib/polyblock/validators.rb
polyblock-0.8.8 lib/polyblock/validators.rb
polyblock-0.8.7 lib/polyblock/validators.rb
polyblock-0.8.6 lib/polyblock/validators.rb
polyblock-0.8.5 lib/polyblock/validators.rb
polyblock-0.8.4 lib/polyblock/validators.rb
polyblock-0.8.3 lib/polyblock/validators.rb
polyblock-0.8.2 lib/polyblock/validators.rb
polyblock-0.8.1 lib/polyblock/validators.rb
polyblock-0.8.0 lib/polyblock/validators.rb