Class: Restify::Relation
- Inherits:
-
Object
- Object
- Restify::Relation
- Defined in:
- lib/restify/relation.rb
Instance Attribute Summary collapse
-
#context ⇒ Restify::Context
readonly
Relation context.
-
#template ⇒ Addressable::Template
readonly
Relation URI template.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete(data = {}, params: {}, **opts) ⇒ Object
- #expand(params) ⇒ Object
- #get(data = {}, params: {}, **opts) ⇒ Object
- #head(data = {}, params: {}, **opts) ⇒ Object
-
#initialize(context, template) ⇒ Relation
constructor
A new instance of Relation.
- #patch(data = nil, **opts) ⇒ Object
- #pattern ⇒ Object
- #post(data = nil, **opts) ⇒ Object
- #put(data = nil, **opts) ⇒ Object
- #request(method:, params: {}, **opts) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(context, template) ⇒ Relation
Returns a new instance of Relation.
17 18 19 20 |
# File 'lib/restify/relation.rb', line 17 def initialize(context, template) @context = context @template = Addressable::Template.new template end |
Instance Attribute Details
#context ⇒ Restify::Context (readonly)
Relation context
9 10 11 |
# File 'lib/restify/relation.rb', line 9 def context @context end |
#template ⇒ Addressable::Template (readonly)
Relation URI template
15 16 17 |
# File 'lib/restify/relation.rb', line 15 def template @template end |
Instance Method Details
#==(other) ⇒ Object
53 54 55 |
# File 'lib/restify/relation.rb', line 53 def ==(other) super || (other.is_a?(String) && template.pattern == other) end |
#delete(data = {}, params: {}, **opts) ⇒ Object
34 35 36 |
# File 'lib/restify/relation.rb', line 34 def delete(data = {}, params: {}, **opts) request(**opts, method: :delete, params: data.merge(params)) end |
#expand(params) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/restify/relation.rb', line 57 def (params) params = convert params variables = extract! params uri = template. variables uri.query_values = (uri.query_values || {}).merge params if params.any? context.join uri end |
#get(data = {}, params: {}, **opts) ⇒ Object
26 27 28 |
# File 'lib/restify/relation.rb', line 26 def get(data = {}, params: {}, **opts) request(**opts, method: :get, params: data.merge(params)) end |
#head(data = {}, params: {}, **opts) ⇒ Object
30 31 32 |
# File 'lib/restify/relation.rb', line 30 def head(data = {}, params: {}, **opts) request(**opts, method: :head, params: data.merge(params)) end |
#patch(data = nil, **opts) ⇒ Object
48 49 50 51 |
# File 'lib/restify/relation.rb', line 48 def patch(data = nil, **opts) opts[:data] = data unless opts.key?(:data) request(**opts, method: :patch) end |
#pattern ⇒ Object
67 68 69 |
# File 'lib/restify/relation.rb', line 67 def pattern template.pattern end |
#post(data = nil, **opts) ⇒ Object
38 39 40 41 |
# File 'lib/restify/relation.rb', line 38 def post(data = nil, **opts) opts[:data] = data unless opts.key?(:data) request(**opts, method: :post) end |
#put(data = nil, **opts) ⇒ Object
43 44 45 46 |
# File 'lib/restify/relation.rb', line 43 def put(data = nil, **opts) opts[:data] = data unless opts.key?(:data) request(**opts, method: :put) end |
#request(method:, params: {}, **opts) ⇒ Object
22 23 24 |
# File 'lib/restify/relation.rb', line 22 def request(method:, params: {}, **opts) context.request(method, (params), **opts) end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/restify/relation.rb', line 71 def to_s pattern end |