Class: ValidateParams::Validatable::ParamValidator
- Inherits:
-
Object
- Object
- ValidateParams::Validatable::ParamValidator
- Defined in:
- lib/validate_params/param_validator.rb
Instance Attribute Summary collapse
-
#validation ⇒ Object
readonly
Returns the value of attribute validation.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(validation:, value:, errors:) ⇒ ParamValidator
constructor
A new instance of ParamValidator.
Constructor Details
#initialize(validation:, value:, errors:) ⇒ ParamValidator
Returns a new instance of ParamValidator.
14 15 16 17 18 19 |
# File 'lib/validate_params/param_validator.rb', line 14 def initialize(validation:, value:, errors:) @validation = validation @value = value @errors = errors = validation..presence || {} end |
Instance Attribute Details
#validation ⇒ Object (readonly)
Returns the value of attribute validation.
12 13 14 |
# File 'lib/validate_params/param_validator.rb', line 12 def validation @validation end |
Class Method Details
.call(**args) ⇒ Object
8 9 10 |
# File 'lib/validate_params/param_validator.rb', line 8 def self.call(**args) new(**args).call end |
Instance Method Details
#call ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/validate_params/param_validator.rb', line 21 def call return if @value.blank? && ![:required] if @value.blank? && [:required] @errors << { message: } return end send(validation.type.to_s.underscore) end |