Class: Swaggable::QueryParams

Inherits:
Delegator
  • Object
show all
Defined in:
lib/swaggable/query_params.rb

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ QueryParams

Returns a new instance of QueryParams.



3
4
5
6
7
8
9
10
# 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

Instance Method Details

#[]=(key, value) ⇒ Object



32
33
34
# File 'lib/swaggable/query_params.rb', line 32

def []= key, value
  self.hash= hash.merge(key => value)
end

#__getobj__Object



12
13
14
# File 'lib/swaggable/query_params.rb', line 12

def __getobj__
  string && hash
end

#hashObject



20
21
22
# File 'lib/swaggable/query_params.rb', line 20

def hash
  parse(string).freeze
end

#hash=(value) ⇒ Object



28
29
30
# File 'lib/swaggable/query_params.rb', line 28

def hash= value
  self.string = serialize(value)
end

#stringObject



16
17
18
# File 'lib/swaggable/query_params.rb', line 16

def string
  @string
end

#string=(value) ⇒ Object



24
25
26
# File 'lib/swaggable/query_params.rb', line 24

def string= value
  @string = value
end