Class: Restify::Resource
- Inherits:
-
Delegator
- Object
- Delegator
- Restify::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/restify/resource.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #__getobj__ ⇒ Object private
- #_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.
11 12 13 14 15 16 |
# File 'lib/restify/resource.rb', line 11 def initialize(context, response: nil, data: nil, relations: {}) @data = data @context = context @response = response @relations = relations end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
58 59 60 |
# File 'lib/restify/resource.rb', line 58 def data @data end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
67 68 69 |
# File 'lib/restify/resource.rb', line 67 def response @response end |
Instance Method Details
#__getobj__ ⇒ 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.
20 21 22 |
# File 'lib/restify/resource.rb', line 20 def __getobj__ @data end |
#_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.
95 96 97 |
# File 'lib/restify/resource.rb', line 95 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.
100 101 102 |
# File 'lib/restify/resource.rb', line 100 def _restify_response=(response) @response = response end |
#follow ⇒ Relation
Follow a LOCATION or CONTEXT-LOCATION header.
73 74 75 76 77 78 79 |
# File 'lib/restify/resource.rb', line 73 def follow if relation? :_restify_follow relation :_restify_follow else nil end end |
#follow! ⇒ Relation
Follow a LOCATION or CONTEXT-LOCATION header.
86 87 88 89 90 91 92 |
# File 'lib/restify/resource.rb', line 86 def follow! if (rel = follow) rel else raise RuntimeError.new '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.
105 106 107 108 109 110 111 112 |
# File 'lib/restify/resource.rb', line 105 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.
42 43 44 45 46 47 48 |
# File 'lib/restify/resource.rb', line 42 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.
29 30 31 |
# File 'lib/restify/resource.rb', line 29 def relation?(name) @relations.key?(name) || @relations.key?(name.to_s) end |