Class: Rack::Utils::KeySpaceConstrainedParams
- Defined in:
- lib/vendor/rack-1.5.2/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.
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
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
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_hash ⇒ Object
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 |