Class: Ward::DSL::ValidationBlock
- Inherits:
- Support::BasicObject
- Defined in:
- lib/ward/dsl/validation_block.rb
Overview
Creates one or more validators using a block.
Instance Method Summary collapse
-
#initialize(set = nil, &block) ⇒ ValidationBlock
constructor
Creates a new ValidationBlock instance.
-
#to_validator_set ⇒ Ward::ValidatorSet
Returns the ValidatorSet created by the DSL.
Methods inherited from Support::BasicObject
Constructor Details
#initialize(set = nil, &block) ⇒ ValidationBlock
Creates a new ValidationBlock instance.
NOTE: Providing an existing ValidatorSet will result in a copy of that set being mutated; the original will not be changed.
29 30 31 32 |
# File 'lib/ward/dsl/validation_block.rb', line 29 def initialize(set = nil, &block) @set = if set.nil? then Ward::ValidatorSet.new else set.dup end run(&block) if block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *extra_args, &block) ⇒ Ward::DSL::ValidationBuilder (private)
Provides the DSL.
Will take the given message and creates a new ValidationBuilder.
62 63 64 65 66 67 68 69 |
# File 'lib/ward/dsl/validation_block.rb', line 62 def method_missing(method, *extra_args, &block) raise 'ValidationBlock can only be used when provided ' \ 'with a block' if @builders.nil? builder = ValidationBuilder.new.__send__(method, *extra_args, &block) @builders.push(builder) builder end |
Instance Method Details
#to_validator_set ⇒ Ward::ValidatorSet
Returns the ValidatorSet created by the DSL.
38 39 40 |
# File 'lib/ward/dsl/validation_block.rb', line 38 def to_validator_set @set end |