Class: Reaction::ValidatorBuilder
- Inherits:
-
Object
- Object
- Reaction::ValidatorBuilder
- Defined in:
- lib/reaction/validator_builder.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#validator ⇒ Object
Returns the value of attribute validator.
Instance Method Summary collapse
- #build(action) ⇒ Object
- #class_for_validator(validator) ⇒ Object
- #class_for_validator!(validator) ⇒ Object
-
#initialize(validator, options = {}) ⇒ ValidatorBuilder
constructor
A new instance of ValidatorBuilder.
Constructor Details
#initialize(validator, options = {}) ⇒ ValidatorBuilder
Returns a new instance of ValidatorBuilder.
6 7 8 9 |
# File 'lib/reaction/validator_builder.rb', line 6 def initialize(validator, = {}) @validator = class_for_validator!(validator) @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/reaction/validator_builder.rb', line 4 def @options end |
#validator ⇒ Object
Returns the value of attribute validator.
3 4 5 |
# File 'lib/reaction/validator_builder.rb', line 3 def validator @validator end |
Instance Method Details
#build(action) ⇒ Object
11 12 13 |
# File 'lib/reaction/validator_builder.rb', line 11 def build(action) validator.new(action, ) end |
#class_for_validator(validator) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/reaction/validator_builder.rb', line 15 def class_for_validator(validator) return validator if validator.is_a?(Class) name = validator.to_s.split('_').map(&:capitalize).join Module.const_get("#{name}Validator") rescue NameError nil end |
#class_for_validator!(validator) ⇒ Object
23 24 25 |
# File 'lib/reaction/validator_builder.rb', line 23 def class_for_validator!(validator) class_for_validator(validator) or raise ArgumentError.new("Unknown validator: #{validator}") end |