Class: TerraformEnterprise::API::Resource
- Inherits:
-
Object
- Object
- TerraformEnterprise::API::Resource
- Defined in:
- lib/terraform_enterprise/api/resource.rb
Overview
A class wrapper for JSON-API resources
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #attributes ⇒ Object
- #data ⇒ Object
- #errors ⇒ Object
- #errors? ⇒ Boolean
- #id ⇒ Object
- #included ⇒ Object
-
#initialize(body) ⇒ Resource
constructor
A new instance of Resource.
- #links ⇒ Object
- #relationships ⇒ Object
- #type ⇒ Object
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
#body ⇒ Object (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
#attributes ⇒ Object
27 28 29 |
# File 'lib/terraform_enterprise/api/resource.rb', line 27 def attributes data['attributes'] || {} end |
#data ⇒ Object
15 16 17 |
# File 'lib/terraform_enterprise/api/resource.rb', line 15 def data @body['data'] end |
#errors ⇒ Object
39 40 41 |
# File 'lib/terraform_enterprise/api/resource.rb', line 39 def errors data['errors'] || [] end |
#errors? ⇒ Boolean
11 12 13 |
# File 'lib/terraform_enterprise/api/resource.rb', line 11 def errors? !errors.empty? end |
#id ⇒ Object
19 20 21 |
# File 'lib/terraform_enterprise/api/resource.rb', line 19 def id data['id'] end |
#included ⇒ Object
43 44 45 |
# File 'lib/terraform_enterprise/api/resource.rb', line 43 def included (body['included'] || []).map{ |resource| Resource.new('data' => resource)} end |
#links ⇒ Object
35 36 37 |
# File 'lib/terraform_enterprise/api/resource.rb', line 35 def links data['links'] || [] end |
#relationships ⇒ Object
31 32 33 |
# File 'lib/terraform_enterprise/api/resource.rb', line 31 def relationships data['relationships'] || {} end |
#type ⇒ Object
23 24 25 |
# File 'lib/terraform_enterprise/api/resource.rb', line 23 def type data['type'] end |