class Rack::QueryParser::Params
Public Class Methods
new(limit)
click to toggle source
# File lib/rack/query_parser.rb, line 158 def initialize(limit) @limit = limit @size = 0 @params = {} end
Public Instance Methods
[](key)
click to toggle source
# File lib/rack/query_parser.rb, line 164 def [](key) @params[key] end
[]=(key, value)
click to toggle source
# File lib/rack/query_parser.rb, line 168 def []=(key, value) @size += key.size if key && !@params.key?(key) raise RangeError, 'exceeded available parameter key space' if @size > @limit @params[key] = value end
key?(key)
click to toggle source
# File lib/rack/query_parser.rb, line 174 def key?(key) @params.key?(key) end
to_h()
click to toggle source
Recursively unwraps nested `Params` objects and constructs an object of the same shape, but using the objects' internal representations (Ruby hashes) in place of the objects. The result is a hash consisting purely of Ruby primitives.
Mutation warning! 1. This method mutates the internal representation of the `Params` objects in order to save object allocations. 2. The value you get back is a reference to the internal hash representation, not a copy. 3. Because the `Params` object's internal representation is mutable through the `#[]=` method, it is not thread safe. The result of getting the hash representation while another thread is adding a key to it is non-deterministic.
# File lib/rack/query_parser.rb, line 196 def to_h @params.each do |key, value| case value when self # Handle circular references gracefully. @params[key] = @params when Params @params[key] = value.to_h when Array value.map! { |v| v.kind_of?(Params) ? v.to_h : v } else # Ignore anything that is not a `Params` object or # a collection that can contain one. end end @params end
Also aliased as: to_params_hash