lib/whyvalidationssuckin96/validation_builder.rb in whyvalidationssuckin96-1.3.1 vs lib/whyvalidationssuckin96/validation_builder.rb in whyvalidationssuckin96-1.4.0
- old
+ new
@@ -1,9 +1,10 @@
require 'whyvalidationssuckin96/validation'
module WhyValidationsSuckIn96
class ValidationBuilder
+ RegisteredMacros = {}
# @param [Module, Class] klass_or_mod The Class or Module to add validations to
# @param [Proc] definition_block The block to evaluate to define validations
def initialize(klass_or_mod, definition_block)
@klass_or_mod = klass_or_mod
@@ -16,9 +17,10 @@
# Registers a macro to be used in setup_validations blocks
# @param [Symbol] macro_name The name to register this macro with
# @param [Class] validation_class The class implementing the validation
def self.register_macro(macro_name, validation_class)
+ RegisteredMacros[macro_name] = validation_class
define_method(macro_name) do |*args|
attrs, options = extract_options(args)
attrs.each do |attr|
add_validation(validation_class, options.merge(:attribute => attr))
end