lib/grape/dsl/inside_route.rb
# A filtering method that will return a hash
# consisting only of keys that have been declared by a
# `params` statement against the current/target endpoint or parent
# namespaces
#
# @param params [Hash] The initial hash to filter. Usually this will just be `params`
# @param options [Hash] Can pass `:include_missing`, `:stringify` and `:include_parent_namespaces`
# options. `:include_parent_namespaces` defaults to true, hence must be set to false if
# you want only to return params declared against the current/target endpoint
A filtering method that will return a hash
consisting only of keys that have been declared by a
`params` statement against the current/target endpoint or parent
namespaces
A filtering method that will return a hash consisting only of keys that have been declared by a ` params ` statement against the current / target endpoint or parent namespaces
def declared(params, options = {}, declared_params = nil)
        options[:include_missing] = true unless options.key?(:include_missing)
        options[:include_parent_namespaces] = true unless options.key?(:include_parent_namespaces)
        if declared_params.nil?
          declared_params = (!options[:include_parent_namespaces] ? route_setting(:declared_params) :
              (route_setting(:saved_declared_params) || [])).flatten(1) || []
        end
        unless declared_params
          fail ArgumentError, 'Tried to filter for declared parameters but none exist.'
        end
        if params.is_a? Array
          params.map do |param|
            declared(param || {}, options, declared_params)
          end
        else
          declared_params.inject({}) do |hash, key|
            key = { key => nil } unless key.is_a? Hash
            key.each_pair do |parent, children|
              output_key = options[:stringify] ? parent.to_s : parent.to_sym
              next unless options[:include_missing] || children || params.key?(parent)
              if params.key?(parent) || options[:include_missing]
                hash[output_key] = if children
                                     declared(params[parent] || {}, options, Array(children))
                                   else
                                     params[parent]
                                   end
              end
            end
            hash
          end
        end
      end
def declared ( params , options = { } , declared_params = nil ) options [ :include_missing ] = true unless options . key? ( :include_missing ) options [ :include_parent_namespaces ] = true unless options . key? ( :include_parent_namespaces ) if declared_params . nil? declared_params = ( ! options [ :include_parent_namespaces ] ? route_setting ( :declared_params ) : ( route_setting ( :saved_declared_params ) || [ ] ) ) . flatten ( 1 ) || [ ] end unless declared_params fail ArgumentError , 'Tried to filter for declared parameters but none exist.' end if params . is_a? Array params . map do | param | declared ( param || { } , options , declared_params ) end else declared_params . inject ( { } ) do | hash , key | key = { key => nil } unless key . is_a? Hash key . each_pair do | parent , children | output_key = options [ :stringify ] ? parent . to_s : parent . to_sym next unless options [ :include_missing ] || children || params . key? ( parent ) if params . key? ( parent ) || options [ :include_missing ] hash [ output_key ] = if children declared ( params [ parent ] || { } , options , Array ( children ) ) else params [ parent ] end end end hash end end end
A filtering method that will return a hash
consisting only of keys that have been declared by a
`params` statement against the current/target endpoint or parent
namespaces
A filtering method that will return a hash consisting only of keys that have been declared by a ` params ` statement against the current / target endpoint or parent namespaces
params
The initial hash to filter. Usually this will just be `params`
The initial hash to filter . Usually this will just be ` params `
options
Can pass `:include_missing`, `:stringify` and `:include_parent_namespaces` options. `:include_parent_namespaces` defaults to true, hence must be set to false if you want only to return params declared against the current/target endpoint
Can pass ` : include_missing ` ` : stringify ` and ` : include_parent_namespaces ` options . ` : include_parent_namespaces ` defaults to true hence must be set to false if you want only to return params declared against the current / target endpoint
true, hence must be set to false if you want only to return params declared against the current/target endpoint
declared_params
<not_specific>