Class: Rack::Utils::KeySpaceConstrainedParams

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/rack-1.5.2/lib/rack/utils.rb

Instance Method Summary collapse

Constructor Details

#initialize(limit = Utils.key_space_limit) ⇒ KeySpaceConstrainedParams

Returns a new instance of KeySpaceConstrainedParams.



505
506
507
508
509
# File 'lib/vendor/rack-1.5.2/lib/rack/utils.rb', line 505

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

Instance Method Details

#[](key) ⇒ Object



511
512
513
# File 'lib/vendor/rack-1.5.2/lib/rack/utils.rb', line 511

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

#[]=(key, value) ⇒ Object

Raises:

  • (RangeError)


515
516
517
518
519
# File 'lib/vendor/rack-1.5.2/lib/rack/utils.rb', line 515

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

Returns:

  • (Boolean)


521
522
523
# File 'lib/vendor/rack-1.5.2/lib/rack/utils.rb', line 521

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

#to_params_hashObject



525
526
527
528
529
530
531
532
533
534
535
536
# File 'lib/vendor/rack-1.5.2/lib/rack/utils.rb', line 525

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