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