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
- #head(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.
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
50 51 52 |
# File 'lib/restify/relation.rb', line 50 def ==(other) super || (other.is_a?(String) && template.pattern == other) end |
#delete(params = {}, opts = {}) ⇒ Object
34 35 36 |
# File 'lib/restify/relation.rb', line 34 def delete(params = {}, opts = {}) request :delete, nil, params, opts end |
#expand(params) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/restify/relation.rb', line 54 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
26 27 28 |
# File 'lib/restify/relation.rb', line 26 def get(params = {}, opts = {}) request :get, nil, params, opts end |
#head(params = {}, opts = {}) ⇒ Object
30 31 32 |
# File 'lib/restify/relation.rb', line 30 def head(params = {}, opts = {}) request :head, nil, params, opts end |
#patch(data = {}, params = {}, opts = {}) ⇒ Object
46 47 48 |
# File 'lib/restify/relation.rb', line 46 def patch(data = {}, params = {}, opts = {}) request :patch, data, params, opts end |
#pattern ⇒ Object
64 65 66 |
# File 'lib/restify/relation.rb', line 64 def pattern template.pattern end |
#post(data = {}, params = {}, opts = {}) ⇒ Object
38 39 40 |
# File 'lib/restify/relation.rb', line 38 def post(data = {}, params = {}, opts = {}) request :post, data, params, opts end |
#put(data = {}, params = {}, opts = {}) ⇒ Object
42 43 44 |
# File 'lib/restify/relation.rb', line 42 def put(data = {}, params = {}, opts = {}) request :put, data, params, opts end |
#request(method, data, params, opts = {}) ⇒ Object
22 23 24 |
# File 'lib/restify/relation.rb', line 22 def request(method, data, params, opts = {}) context.request method, (params), **opts, data: data end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/restify/relation.rb', line 68 def to_s pattern end |