Sha256: dc134008c379a1383604e91e3a3170bac3159ee7abe737132ddf36b767494156

Contents?: true

Size: 1.17 KB

Versions: 36

Compression:

Stored size: 1.17 KB

Contents

require 'active_model'
require 'active_support/concern'
require 'active_support/core_ext/array/wrap'
require 'polygallery/validators/polygallery_presence_validator'

module Polygallery
  module Validators
    extend ActiveSupport::Concern

    included do
      extend  HelperMethods
      include HelperMethods
    end

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

        Polygallery::Validators.constants.each do |constant|
          if constant.to_s =~ /\APolygallery(.+)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 = Polygallery::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

36 entries across 36 versions & 1 rubygems

Version Path
polygallery-0.4.8 lib/polygallery/validators.rb
polygallery-0.4.7 lib/polygallery/validators.rb
polygallery-0.4.6 lib/polygallery/validators.rb
polygallery-0.4.5 lib/polygallery/validators.rb
polygallery-0.4.4 lib/polygallery/validators.rb
polygallery-0.4.2 lib/polygallery/validators.rb
polygallery-0.4.1 lib/polygallery/validators.rb
polygallery-0.4.0 lib/polygallery/validators.rb
polygallery-0.3.6 lib/polygallery/validators.rb
polygallery-0.3.5 lib/polygallery/validators.rb
polygallery-0.3.4 lib/polygallery/validators.rb
polygallery-0.3.3 lib/polygallery/validators.rb
polygallery-0.3.2 lib/polygallery/validators.rb
polygallery-0.3.1 lib/polygallery/validators.rb
polygallery-0.3.0 lib/polygallery/validators.rb
polygallery-0.2.5 lib/polygallery/validators.rb
polygallery-0.2.4 lib/polygallery/validators.rb
polygallery-0.2.3 lib/polygallery/validators.rb
polygallery-0.2.1 lib/polygallery/validators.rb
polygallery-0.1.9 lib/polygallery/validators.rb