Class: JSON_ROA::Client::Resource
- Inherits:
-
Object
- Object
- JSON_ROA::Client::Resource
- Defined in:
- lib/json_roa/client/resource.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #collection ⇒ Object
- #data ⇒ Object
-
#initialize(conn, response = nil) ⇒ Resource
constructor
A new instance of Resource.
- #json_roa_data ⇒ Object
- #relation(key) ⇒ Object
- #self_relation ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(conn, response = nil) ⇒ Resource
Returns a new instance of Resource.
12 13 14 15 |
# File 'lib/json_roa/client/resource.rb', line 12 def initialize(conn, response = nil) @conn = conn @response = response || conn.get end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
9 10 11 |
# File 'lib/json_roa/client/resource.rb', line 9 def conn @conn end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/json_roa/client/resource.rb', line 10 def response @response end |
Instance Method Details
#collection ⇒ Object
39 40 41 |
# File 'lib/json_roa/client/resource.rb', line 39 def collection ::JSON_ROA::Client::Collection.new @conn, self end |
#data ⇒ Object
27 28 29 30 31 |
# File 'lib/json_roa/client/resource.rb', line 27 def data @response.body.instance_eval do self.with_indifferent_access rescue self end end |
#json_roa_data ⇒ Object
33 34 35 36 37 |
# File 'lib/json_roa/client/resource.rb', line 33 def json_roa_data @response.env.json_roa_data.instance_eval do self.with_indifferent_access rescue self end end |
#relation(key) ⇒ Object
17 18 19 20 |
# File 'lib/json_roa/client/resource.rb', line 17 def relation(key) relhash = json_roa_data['relations'][key] ::JSON_ROA::Client::Relation.new @conn, key, relhash end |
#self_relation ⇒ Object
22 23 24 25 |
# File 'lib/json_roa/client/resource.rb', line 22 def self_relation ::JSON_ROA::Client::Relation.new( \ @conn, 'self', json_roa_data['self-relation']) rescue nil end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/json_roa/client/resource.rb', line 43 def to_s "#{self.class.name}: #{data} #{json_roa_data}" end |