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

Instance Method Summary collapse

Instance Attribute Details

#paramsResult (readonly)

Returns the validated params, including errors

Returns:

  • (Result)

    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, options = {}, &block)
    super(name, params || request.params, options, &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, options = {}, &block)
    super(name, params || request.params, options, &block)
  end
end

Instance Method Details

#validate(name, options = {}) ⇒ Result #validate(options = {}) { ... } ⇒ Result

validates Request#params against a validator.

Overloads:

  • #validate(name, options = {}) ⇒ Result

    Returns a result hash containing the extracted keys, and any errors.

    Parameters:

    • name (Symbol)

      the name of a registered validator.

    • options (Hash) (defaults to: {})

    Returns:

    • (Result)

      a result hash containing the extracted keys, and any errors.

    Raises:

  • #validate(options = {}) { ... } ⇒ Result

    validates the given parameters against the given block

    Parameters:

    • options (Hash) (defaults to: {})

    Yields:

    • a code block that will run in the context of a HashContext to validate the params

    Returns:

    • (Result)

      a result hash containing the extracted keys, and any errors.

    Raises:



112
113
114
# File 'lib/rack/params.rb', line 112

def validate(name = nil, params = nil, options = {}, &block)
  super(name, params || request.params, options, &block)
end

#validate!(name, options = {}) ⇒ Result #validate!(options = {}) { ... } ⇒ Result

validates Request#params against a validator, raising on errors.

Overloads:

  • #validate!(name, options = {}) ⇒ Result

    Returns a valid result hash containing the extracted keys, and no errors.

    Parameters:

    • name (Symbol)

      the name of a registered validator.

    • options (Hash) (defaults to: {})

    Returns:

    • (Result)

      a valid result hash containing the extracted keys, and no errors.

    Raises:

  • #validate!(options = {}) { ... } ⇒ Result

    validates the given parameters against the given block

    Parameters:

    • options (Hash) (defaults to: {})

    Yields:

    • a code block that will run in the context of a HashContext to validate the params

    Returns:

    • (Result)

      a valid result hash containing the extracted keys, and no errors.

    Raises:



128
129
130
# File 'lib/rack/params.rb', line 128

def validate!(name = nil, params = nil, options = {}, &block)
  super(name, params || request.params, options, &block)
end