Module: Rack::Params::Connector
- Defined in:
- lib/rack/params.rb
Overview
mixin for frameworks that have a #request method in scope make sure you `include Rack::Params` before including
Instance Attribute Summary collapse
-
#params ⇒ Result
readonly
The validated params, including errors.
Instance Method Summary collapse
-
#validate(name = nil, params = nil, options = {}, &block) ⇒ Object
validates Request#params against a validator.
-
#validate!(name = nil, params = nil, options = {}, &block) ⇒ Object
validates Request#params against a validator, raising on errors.
Instance Attribute Details
#params ⇒ Result (readonly)
Returns the validated params, including errors
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rack/params.rb', line 93 module Connector def self.included(base) base.class_eval do attr_reader :params end end # validates {Rack::Request#params} against a validator. # @overload validate(name, options = {}) # @param [Symbol] name the name of a registered validator. # @param [Hash] options # @return [Result] a result hash containing the extracted keys, and any errors. # @raise [ParameterValidationError] if the parameters are invalid after validation and coercion # @overload validate(options = {}, &block) # validates the given parameters against the given block # @param [Hash] options # @yield a code block that will run in the context of a {Rack::Params::HashContext} to validate the params # @return [Result] a result hash containing the extracted keys, and any errors. # @raise [ParameterValidationError] if the parameters are invalid after validation and coercion def validate(name = nil, params = nil, = {}, &block) super(name, params || request.params, , &block) end # validates {Rack::Request#params} against a validator, raising on errors. # @overload validate!(name, options = {}) # @param [Symbol] name the name of a registered validator. # @param [Hash] options # @return [Result] a valid result hash containing the extracted keys, and no errors. # @raise [ParameterValidationError] if the parameters are invalid after validation and coercion # @overload validate!(options = {}, &block) # validates the given parameters against the given block # @param [Hash] options # @yield a code block that will run in the context of a {Rack::Params::HashContext} to validate the params # @return [Result] a valid result hash containing the extracted keys, and no errors. # @raise [ParameterValidationError] if the parameters are invalid after validation and coercion def validate!(name = nil, params = nil, = {}, &block) super(name, params || request.params, , &block) end end |
Instance Method Details
#validate(name, options = {}) ⇒ Result #validate(options = {}) { ... } ⇒ Result
validates Request#params against a validator.
112 113 114 |
# File 'lib/rack/params.rb', line 112 def validate(name = nil, params = nil, = {}, &block) super(name, params || request.params, , &block) end |
#validate!(name, options = {}) ⇒ Result #validate!(options = {}) { ... } ⇒ Result
validates Request#params against a validator, raising on errors.
128 129 130 |
# File 'lib/rack/params.rb', line 128 def validate!(name = nil, params = nil, = {}, &block) super(name, params || request.params, , &block) end |