Class: Rack::QueryParser::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/query_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(limit) ⇒ Params


156
157
158
159
160
# File 'lib/rack/query_parser.rb', line 156

def initialize(limit)
  @limit  = limit
  @size   = 0
  @params = {}
end

Instance Method Details

#[](key) ⇒ Object


162
163
164
# File 'lib/rack/query_parser.rb', line 162

def [](key)
  @params[key]
end

#[]=(key, value) ⇒ Object

Raises:

  • (RangeError)

166
167
168
169
170
# File 'lib/rack/query_parser.rb', line 166

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) ⇒ Boolean


172
173
174
# File 'lib/rack/query_parser.rb', line 172

def key?(key)
  @params.key?(key)
end

#to_params_hashObject


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rack/query_parser.rb', line 176

def to_params_hash
  hash = @params
  hash.keys.each do |key|
    value = hash[key]
    if value.kind_of?(self.class)
      if value.object_id == self.object_id
        hash[key] = hash
      else
        hash[key] = value.to_params_hash
      end
    elsif value.kind_of?(Array)
      value.map! {|x| x.kind_of?(self.class) ? x.to_params_hash : x}
    end
  end
  hash
end