Class: WeakParameters::BaseValidator
- Inherits:
-
Object
- Object
- WeakParameters::BaseValidator
- Defined in:
- lib/weak_parameters/base_validator.rb
Direct Known Subclasses
AnyValidator, ArrayValidator, BooleanValidator, FileValidator, FloatValidator, HashValidator, IntegerValidator, StringValidator
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(controller, key, options = {}, &block) ⇒ BaseValidator
constructor
A new instance of BaseValidator.
- #key ⇒ Object
- #required? ⇒ Boolean
- #type ⇒ Object
- #validate(*path) ⇒ Object
Constructor Details
#initialize(controller, key, options = {}, &block) ⇒ BaseValidator
5 6 7 8 9 10 |
# File 'lib/weak_parameters/base_validator.rb', line 5 def initialize(controller, key, = {}, &block) @controller = controller @key = key @options = @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/weak_parameters/base_validator.rb', line 3 def block @block end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/weak_parameters/base_validator.rb', line 3 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/weak_parameters/base_validator.rb', line 3 def @options end |
Instance Method Details
#key ⇒ Object
25 26 27 |
# File 'lib/weak_parameters/base_validator.rb', line 25 def key path[-1] end |
#required? ⇒ Boolean
17 18 19 |
# File 'lib/weak_parameters/base_validator.rb', line 17 def required? !![:required] end |
#type ⇒ Object
21 22 23 |
# File 'lib/weak_parameters/base_validator.rb', line 21 def type self.class.name.split("::").last.sub(/Validator$/, "").underscore.to_sym end |
#validate(*path) ⇒ Object
12 13 14 15 |
# File 'lib/weak_parameters/base_validator.rb', line 12 def validate(*path) @path = path handle_failure unless valid? end |