lib/grape/validations/validators/base.rb in grape-0.17.0 vs lib/grape/validations/validators/base.rb in grape-0.18.0
- old
+ new
@@ -8,24 +8,27 @@
# parameter definition.
# @param attrs [Array] names of attributes to which the Validator applies
# @param options [Object] implementation-dependent Validator options
# @param required [Boolean] attribute(s) are required or optional
# @param scope [ParamsScope] parent scope for this Validator
- def initialize(attrs, options, required, scope)
+ # @param opts [Hash] additional validation options
+ def initialize(attrs, options, required, scope, opts = {})
@attrs = Array(attrs)
@option = options
@required = required
@scope = scope
+ @fail_fast = opts[:fail_fast] || false
end
# Validates a given request.
# @note This method must be thread-safe.
# @note Override #validate! unless you need to access the entire request.
# @param request [Grape::Request] the request currently being handled
# @raise [Grape::Exceptions::Validation] if validation failed
# @return [void]
def validate(request)
+ return unless @scope.should_validate?(request.params)
validate!(request.params)
end
# Validates a given parameter hash.
# @note This method must be thread-safe.
@@ -72,9 +75,13 @@
end
def options_key?(key, options = nil)
options = instance_variable_get(:@option) if options.nil?
options.respond_to?(:key?) && options.key?(key) && !options[key].nil?
+ end
+
+ def fail_fast?
+ @fail_fast
end
end
end
end