Class: PusherPlatform::QueryParser::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher-platform/rack_query_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(limit) ⇒ Params

Returns a new instance of Params.



180
181
182
183
184
# File 'lib/pusher-platform/rack_query_parser.rb', line 180

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

Instance Method Details

#[](key) ⇒ Object



186
187
188
# File 'lib/pusher-platform/rack_query_parser.rb', line 186

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

#[]=(key, value) ⇒ Object

Raises:

  • (RangeError)


190
191
192
193
194
# File 'lib/pusher-platform/rack_query_parser.rb', line 190

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)


196
197
198
# File 'lib/pusher-platform/rack_query_parser.rb', line 196

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

#to_params_hashObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/pusher-platform/rack_query_parser.rb', line 200

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