Class: WeakParameters::BaseValidator
- Inherits:
-
Object
- Object
- WeakParameters::BaseValidator
- Defined in:
- lib/weak_parameters/base_validator.rb
Direct Known Subclasses
AnyValidator, ArrayValidator, BooleanValidator, 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.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#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.
- #required? ⇒ Boolean
- #type ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(controller, key, options = {}, &block) ⇒ BaseValidator
Returns a new instance of 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 = @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 |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/weak_parameters/base_validator.rb', line 3 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/weak_parameters/base_validator.rb', line 3 def end |
Instance Method Details
#required? ⇒ Boolean
16 17 18 |
# File 'lib/weak_parameters/base_validator.rb', line 16 def required? !![:required] end |
#type ⇒ Object
20 21 22 |
# File 'lib/weak_parameters/base_validator.rb', line 20 def type self.class.name.split("::").last.sub(/Validator$/, "").underscore.to_sym end |
#validate ⇒ Object
12 13 14 |
# File 'lib/weak_parameters/base_validator.rb', line 12 def validate handle_failure unless valid? end |