Class: WeakParameters::BaseValidator
- Inherits:
-
Object
- Object
- WeakParameters::BaseValidator
- Defined in:
- lib/weak_parameters/base_validator.rb
Direct Known Subclasses
ArrayValidator, BooleanValidator, HashValidator, IntegerValidator, StringValidator
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(params, key, options = {}) ⇒ BaseValidator
constructor
A new instance of BaseValidator.
- #required? ⇒ Boolean
- #type ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(params, key, options = {}) ⇒ BaseValidator
Returns a new instance of BaseValidator.
5 6 7 8 9 |
# File 'lib/weak_parameters/base_validator.rb', line 5 def initialize(params, key, = {}) @params = params @key = key @options = end |
Instance Attribute Details
#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 @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/weak_parameters/base_validator.rb', line 3 def params @params end |
Instance Method Details
#required? ⇒ Boolean
15 16 17 |
# File 'lib/weak_parameters/base_validator.rb', line 15 def required? !![:required] end |
#type ⇒ Object
19 20 21 |
# File 'lib/weak_parameters/base_validator.rb', line 19 def type self.class.name.split("::").last.sub(/Validator$/, "").underscore.to_sym end |
#validate ⇒ Object
11 12 13 |
# File 'lib/weak_parameters/base_validator.rb', line 11 def validate raise_error if required? && nil? || exist? && invalid_type? end |