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(params = {}, opts = {}) ⇒ Object
- #expand(params) ⇒ Object
- #get(params = {}, opts = {}) ⇒ Object
-
#initialize(context, template) ⇒ Relation
constructor
A new instance of Relation.
- #patch(data = {}, params = {}, opts = {}) ⇒ Object
- #pattern ⇒ Object
- #post(data = {}, params = {}, opts = {}) ⇒ Object
- #put(data = {}, params = {}, opts = {}) ⇒ Object
- #request(method, data, params, opts = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(context, template) ⇒ Relation
Returns a new instance of Relation.
18 19 20 21 |
# File 'lib/restify/relation.rb', line 18 def initialize(context, template) @context = context @template = Addressable::Template.new template end |
Instance Attribute Details
#context ⇒ Restify::Context (readonly)
Relation context
10 11 12 |
# File 'lib/restify/relation.rb', line 10 def context @context end |
#template ⇒ Addressable::Template (readonly)
Relation URI template
16 17 18 |
# File 'lib/restify/relation.rb', line 16 def template @template end |
Instance Method Details
#==(other) ⇒ Object
47 48 49 |
# File 'lib/restify/relation.rb', line 47 def ==(other) super || (other.is_a?(String) && template.pattern == other) end |
#delete(params = {}, opts = {}) ⇒ Object
31 32 33 |
# File 'lib/restify/relation.rb', line 31 def delete(params = {}, opts = {}) request :delete, nil, params, opts end |
#expand(params) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/restify/relation.rb', line 51 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(params = {}, opts = {}) ⇒ Object
27 28 29 |
# File 'lib/restify/relation.rb', line 27 def get(params = {}, opts = {}) request :get, nil, params, opts end |
#patch(data = {}, params = {}, opts = {}) ⇒ Object
43 44 45 |
# File 'lib/restify/relation.rb', line 43 def patch(data = {}, params = {}, opts = {}) request :patch, data, params, opts end |
#pattern ⇒ Object
61 62 63 |
# File 'lib/restify/relation.rb', line 61 def pattern template.pattern end |
#post(data = {}, params = {}, opts = {}) ⇒ Object
35 36 37 |
# File 'lib/restify/relation.rb', line 35 def post(data = {}, params = {}, opts = {}) request :post, data, params, opts end |
#put(data = {}, params = {}, opts = {}) ⇒ Object
39 40 41 |
# File 'lib/restify/relation.rb', line 39 def put(data = {}, params = {}, opts = {}) request :put, data, params, opts end |
#request(method, data, params, opts = {}) ⇒ Object
23 24 25 |
# File 'lib/restify/relation.rb', line 23 def request(method, data, params, opts = {}) context.request method, (params), **opts, data: data end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/restify/relation.rb', line 65 def to_s pattern end |