Class: GrapeSwagger::Endpoint::ParamsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-swagger/endpoint/params_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, settings) ⇒ ParamsParser

Returns a new instance of ParamsParser.



12
13
14
15
# File 'lib/grape-swagger/endpoint/params_parser.rb', line 12

def initialize(params, settings)
  @params = params
  @settings = settings
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/grape-swagger/endpoint/params_parser.rb', line 6

def params
  @params
end

#settingsObject (readonly)

Returns the value of attribute settings.



6
7
8
# File 'lib/grape-swagger/endpoint/params_parser.rb', line 6

def settings
  @settings
end

Class Method Details

.parse_request_params(params, settings) ⇒ Object



8
9
10
# File 'lib/grape-swagger/endpoint/params_parser.rb', line 8

def self.parse_request_params(params, settings)
  new(params, settings).parse_request_params
end

Instance Method Details

#parse_request_paramsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/grape-swagger/endpoint/params_parser.rb', line 17

def parse_request_params
  array_keys = []
  public_params.each_with_object({}) do |(name, options), memo|
    name = name.to_s
    param_type = options[:type]
    param_type = param_type.to_s unless param_type.nil?

    if param_type_is_array?(param_type)
      array_keys << name
      options[:is_array] = true

      name += '[]' if array_use_braces?(options)
    else
      keys = array_keys.find_all { |key| name.start_with? "#{key}[" }
      if keys.any?
        options[:is_array] = true
        if array_use_braces?(options)
          keys.sort.reverse_each do |key|
            name = name.sub(key, "#{key}[]")
          end
        end
      end
    end

    memo[name] = options unless %w[Hash Array].include?(param_type) && !options.key?(:documentation)
  end
end