Class: Rack::Utils::KeySpaceConstrainedParams
- Inherits:
-
Object
- Object
- Rack::Utils::KeySpaceConstrainedParams
- Defined in:
- lib/rack/utils.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(limit = Utils.key_space_limit) ⇒ KeySpaceConstrainedParams
constructor
A new instance of KeySpaceConstrainedParams.
- #key?(key) ⇒ Boolean
- #to_params_hash ⇒ Object
Constructor Details
#initialize(limit = Utils.key_space_limit) ⇒ KeySpaceConstrainedParams
Returns a new instance of KeySpaceConstrainedParams.
440 441 442 443 444 |
# File 'lib/rack/utils.rb', line 440 def initialize(limit = Utils.key_space_limit) @limit = limit @size = 0 @params = {} end |
Instance Method Details
#[](key) ⇒ Object
446 447 448 |
# File 'lib/rack/utils.rb', line 446 def [](key) @params[key] end |
#[]=(key, value) ⇒ Object
450 451 452 453 454 |
# File 'lib/rack/utils.rb', line 450 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
456 457 458 |
# File 'lib/rack/utils.rb', line 456 def key?(key) @params.key?(key) end |
#to_params_hash ⇒ Object
460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/rack/utils.rb', line 460 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 |