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.
15 16 17 18 19 20 |
# File 'lib/validate_params/param_validator.rb', line 15 def initialize(validation:, value:, errors:) @validation = validation @value = value @errors = errors @options = validation..presence || {} end |
Instance Attribute Details
#validation ⇒ Object (readonly)
Returns the value of attribute validation.
13 14 15 |
# File 'lib/validate_params/param_validator.rb', line 13 def validation @validation end |
Class Method Details
.call(**args) ⇒ Object
9 10 11 |
# File 'lib/validate_params/param_validator.rb', line 9 def self.call(**args) new(**args).call end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/validate_params/param_validator.rb', line 22 def call return if @value.nil? && !@options[:required] if @value.blank? && @options[:required] @errors << { message: } return end send(validation.type.to_s.underscore) end |