Class: Bamboo::Client::Http::Json::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/bamboo-client/http/json.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Doc

Returns a new instance of Doc.



14
15
16
17
# File 'lib/bamboo-client/http/json.rb', line 14

def initialize(data)
  @data = data
  pp @data if $DEBUG
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/bamboo-client/http/json.rb', line 8

def data
  @data
end

Class Method Details

.from(str) ⇒ Object



10
11
12
# File 'lib/bamboo-client/http/json.rb', line 10

def self.from(str)
  new JSON.parse(str)
end

Instance Method Details

#auto_expand(klass, client) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bamboo-client/http/json.rb', line 23

def auto_expand(klass, client)
  key_to_expand = @data.fetch('expand')

  obj = @data[key_to_expand]
  case obj
  when Hash
    if obj.has_key?('expand')
      Doc.new(obj).auto_expand(klass, client)
    else
      klass.new(obj, client)
    end
  when Array
    obj.map { |e| klass.new(e, client) }
  else
    raise TypeError, "don't know how to auto-expand #{obj.inspect}"
  end
end

#doc_for(key) ⇒ Object



19
20
21
# File 'lib/bamboo-client/http/json.rb', line 19

def doc_for(key)
  Doc.new @data.fetch(key)
end