Class: Rack::QueryParser::Params
- Inherits:
-
Object
- Object
- Rack::QueryParser::Params
- Defined in:
- lib/rack/query_parser.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(limit) ⇒ Params
constructor
A new instance of Params.
- #key?(key) ⇒ Boolean
- #to_params_hash ⇒ Object
Constructor Details
#initialize(limit) ⇒ Params
Returns a new instance of Params.
154 155 156 157 158 |
# File 'lib/rack/query_parser.rb', line 154 def initialize(limit) @limit = limit @size = 0 @params = {} end |
Instance Method Details
#[](key) ⇒ Object
160 161 162 |
# File 'lib/rack/query_parser.rb', line 160 def [](key) @params[key] end |
#[]=(key, value) ⇒ Object
164 165 166 167 168 |
# File 'lib/rack/query_parser.rb', line 164 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
170 171 172 |
# File 'lib/rack/query_parser.rb', line 170 def key?(key) @params.key?(key) end |
#to_params_hash ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rack/query_parser.rb', line 174 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 |