class Swaggable::QueryParams

Public Class Methods

new(arg = nil) click to toggle source
# File lib/swaggable/query_params.rb, line 3
def initialize arg = nil
  case arg
  when String then self.string = arg
  when Hash then self.hash = arg
  when NilClass then self.hash = {}
  else raise("#{arg.inspect} not supported. Use Hash or String")
  end
end

Public Instance Methods

[]=(key, value) click to toggle source
# File lib/swaggable/query_params.rb, line 32
def []= key, value
  self.hash= hash.merge(key => value)
end
__getobj__() click to toggle source
# File lib/swaggable/query_params.rb, line 12
def __getobj__
  string && hash
end
hash() click to toggle source
# File lib/swaggable/query_params.rb, line 20
def hash
  parse(string).freeze
end
hash=(value) click to toggle source
# File lib/swaggable/query_params.rb, line 28
def hash= value
  self.string = serialize(value)
end
string() click to toggle source
# File lib/swaggable/query_params.rb, line 16
def string
  @string
end
string=(value) click to toggle source
# File lib/swaggable/query_params.rb, line 24
def string= value
  @string = value
end

Private Instance Methods

binding() click to toggle source
# File lib/swaggable/query_params.rb, line 46
def binding
  ::Kernel.binding
end
parse(string) click to toggle source
# File lib/swaggable/query_params.rb, line 42
def parse string
  CGI.parse(string).inject({}){|a,h| k,v = h; a[k]=v.first; a} 
end
serialize(hash) click to toggle source
# File lib/swaggable/query_params.rb, line 38
def serialize hash
  hash.map{|k, v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }.join("&")
end