Class: Grape::Validations::Validator
- Inherits:
-
Object
- Object
- Grape::Validations::Validator
- Defined in:
- lib/grape/validations.rb,
lib/grape/validations.rb
Overview
We define Validator::inherited here so SingleOptionValidator will not be considered a validator.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs, options, required, scope) ⇒ Validator
constructor
A new instance of Validator.
- #validate!(params) ⇒ Object
Constructor Details
#initialize(attrs, options, required, scope) ⇒ Validator
Returns a new instance of Validator.
13 14 15 16 17 18 19 20 21 |
# File 'lib/grape/validations.rb', line 13 def initialize(attrs, , required, scope) @attrs = Array(attrs) @required = required @scope = scope if .is_a?(Hash) && !.empty? raise "unknown options: #{.keys}" end end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
11 12 13 |
# File 'lib/grape/validations.rb', line 11 def attrs @attrs end |
Class Method Details
.inherited(klass) ⇒ Object
58 59 60 61 |
# File 'lib/grape/validations.rb', line 58 def self.inherited(klass) short_name = convert_to_short_name(klass) Validations::register_validator(short_name, klass) end |
Instance Method Details
#validate!(params) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/grape/validations.rb', line 23 def validate!(params) params = @scope.params(params) @attrs.each do |attr_name| if @required || params.has_key?(attr_name) validate_param!(attr_name, params) end end end |