Class: Noder::HTTP::Utils::KeySpaceConstrainedParams
- Inherits:
-
Object
- Object
- Noder::HTTP::Utils::KeySpaceConstrainedParams
- Defined in:
- lib/noder/http/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.
17 18 19 20 21 |
# File 'lib/noder/http/utils.rb', line 17 def initialize(limit = Utils.key_space_limit) @limit = limit @size = 0 @params = {} end |
Instance Method Details
#[](key) ⇒ Object
23 24 25 |
# File 'lib/noder/http/utils.rb', line 23 def [](key) @params[key] end |
#[]=(key, value) ⇒ Object
27 28 29 30 31 |
# File 'lib/noder/http/utils.rb', line 27 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
33 34 35 |
# File 'lib/noder/http/utils.rb', line 33 def key?(key) @params.key?(key) end |
#to_params_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/noder/http/utils.rb', line 37 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 |