Class: TerraformEnterprise::API::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/terraform_enterprise/api/resource.rb

Overview

A class wrapper for JSON-API resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Resource

Returns a new instance of Resource.



7
8
9
# File 'lib/terraform_enterprise/api/resource.rb', line 7

def initialize(body)
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/terraform_enterprise/api/resource.rb', line 5

def body
  @body
end

Instance Method Details

#attributesObject



27
28
29
# File 'lib/terraform_enterprise/api/resource.rb', line 27

def attributes
  data['attributes'] || {}
end

#dataObject



15
16
17
# File 'lib/terraform_enterprise/api/resource.rb', line 15

def data
  @body['data']
end

#errorsObject



39
40
41
# File 'lib/terraform_enterprise/api/resource.rb', line 39

def errors
  data['errors'] || []
end

#errors?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/terraform_enterprise/api/resource.rb', line 11

def errors?
  !errors.empty?
end

#idObject



19
20
21
# File 'lib/terraform_enterprise/api/resource.rb', line 19

def id
  data['id']
end

#includedObject



43
44
45
# File 'lib/terraform_enterprise/api/resource.rb', line 43

def included
  (body['included'] || []).map{ |resource| Resource.new('data' => resource)}
end


35
36
37
# File 'lib/terraform_enterprise/api/resource.rb', line 35

def links
  data['links'] || []
end

#relationshipsObject



31
32
33
# File 'lib/terraform_enterprise/api/resource.rb', line 31

def relationships
  data['relationships'] || {}
end

#typeObject



23
24
25
# File 'lib/terraform_enterprise/api/resource.rb', line 23

def type
  data['type']
end