Class: WhyValidationsSuckIn96::ValidationBuilder
- Inherits:
-
Object
- Object
- WhyValidationsSuckIn96::ValidationBuilder
- Defined in:
- lib/whyvalidationssuckin96/validation_builder.rb
Overview
ValidationBuilder
Class Method Summary
- + (Object) register_macro(macro_name, validation_class) Registers a macro to be used in setup_validations blocks.
Instance Method Summary
- - (Object) create_validations!
- - (ValidationBuilder) initialize(klass_or_mod, definition_block) constructor A new instance of ValidationBuilder.
Constructor Details
- (ValidationBuilder) initialize(klass_or_mod, definition_block)
A new instance of ValidationBuilder
8 9 10 11 |
# File 'lib/whyvalidationssuckin96/validation_builder.rb', line 8 def initialize(klass_or_mod, definition_block) @klass_or_mod = klass_or_mod @definition_block = definition_block end |
Class Method Details
+ (Object) register_macro(macro_name, validation_class)
Registers a macro to be used in setup_validations blocks
20 21 22 23 24 25 26 27 |
# File 'lib/whyvalidationssuckin96/validation_builder.rb', line 20 def self.register_macro(macro_name, validation_class) define_method(macro_name) do |*args| attrs, = (args) attrs.each do |attr| add_validation(validation_class, .merge(:attribute => attr)) end end end |
Instance Method Details
- (Object) create_validations!
13 14 15 |
# File 'lib/whyvalidationssuckin96/validation_builder.rb', line 13 def create_validations! instance_eval(&@definition_block) end |