class RackOnLambda::Query
The `multiValueQueryStringParameters` object from the API Gateway event keeps all values in an array, regardless of the actual size of the array and regardless of the “intent” of the query string parameter.
In order to normalise this behaviour, we treat the query strings
`key=value1&key=value2`
and
`key[]=value1&key[]=value2`
the same. Both are to be serialised to the query string
`key[]=value1&key[]=value2`
However, the query strings
`key=value`
and
`key[]=value`
are not to be treated the same.
Public Class Methods
new(data = {})
click to toggle source
# File lib/rack_on_lambda/query.rb, line 30 def initialize(data = {}) @params = data.with_indifferent_access end
Public Instance Methods
add(key, values)
click to toggle source
# File lib/rack_on_lambda/query.rb, line 34 def add(key, values) if key.to_s.end_with?('[]') actual_key = key[0..-3] add_list(actual_key, values) else values.each { |value| add_item(key, value) } end end
to_h()
click to toggle source
# File lib/rack_on_lambda/query.rb, line 43 def to_h @params.dup end
to_s()
click to toggle source
# File lib/rack_on_lambda/query.rb, line 47 def to_s Rack::Utils.build_nested_query(to_h) end
Private Instance Methods
add_item(key, value)
click to toggle source
# File lib/rack_on_lambda/query.rb, line 53 def add_item(key, value) if @params[key].nil? @params[key] = value else @params[key] = Array(@params[key]) @params[key] << value end end
add_list(key, value)
click to toggle source
# File lib/rack_on_lambda/query.rb, line 62 def add_list(key, value) @params[key] ||= [] @params[key].concat(value) end