Class: Restify::Resource
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Restify::Resource
- Defined in:
- lib/restify/resource.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #_restify_relations ⇒ Object private
- #_restify_response=(response) ⇒ Object private
-
#follow ⇒ Relation
Follow a LOCATION or CONTEXT-LOCATION header.
-
#follow! ⇒ Relation
Follow a LOCATION or CONTEXT-LOCATION header.
-
#initialize(context, response: nil, data: nil, relations: {}) ⇒ Resource
constructor
private
A new instance of Resource.
- #inspect ⇒ Object private
-
#relation(name) ⇒ Relation
(also: #rel)
Return relation with given name.
-
#relation?(name) ⇒ Boolean
(also: #rel?, #has_rel?, #has_relation?)
Check if resource has a relation with given name.
Constructor Details
#initialize(context, response: nil, data: nil, relations: {}) ⇒ Resource
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Resource.
9 10 11 12 13 14 15 |
# File 'lib/restify/resource.rb', line 9 def initialize(context, response: nil, data: nil, relations: {}) super(data) @context = context @response = response @relations = relations end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
60 61 62 |
# File 'lib/restify/resource.rb', line 60 def response @response end |
Instance Method Details
#_restify_relations ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/restify/resource.rb', line 86 def _restify_relations @relations end |
#_restify_response=(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 |
# File 'lib/restify/resource.rb', line 91 def _restify_response=(response) @response = response end |
#follow ⇒ Relation
Follow a LOCATION or CONTEXT-LOCATION header.
66 67 68 |
# File 'lib/restify/resource.rb', line 66 def follow relation :_restify_follow if relation? :_restify_follow end |
#follow! ⇒ Relation
Follow a LOCATION or CONTEXT-LOCATION header.
rubocop:disable Style/GuardClause
76 77 78 79 80 81 82 |
# File 'lib/restify/resource.rb', line 76 def follow! if (rel = follow) rel else raise 'Nothing to follow' end end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 99 100 101 102 103 |
# File 'lib/restify/resource.rb', line 96 def inspect text = { '@data' => data, '@relations' => @relations }.map {|k, v| k + '=' + v.inspect }.join(' ') "#<#{self.class} #{text}>" end |
#relation(name) ⇒ Relation Also known as: rel
Return relation with given name.
35 36 37 38 39 40 41 |
# File 'lib/restify/resource.rb', line 35 def relation(name) if @relations.key? name Relation.new @context, @relations.fetch(name) else Relation.new @context, @relations.fetch(name.to_s) end end |
#relation?(name) ⇒ Boolean Also known as: rel?, has_rel?, has_relation?
Check if resource has a relation with given name.
22 23 24 |
# File 'lib/restify/resource.rb', line 22 def relation?(name) @relations.key?(name) || @relations.key?(name.to_s) end |