Class: Pillow::Method
- Inherits:
-
Object
- Object
- Pillow::Method
- Defined in:
- lib/pillow/method.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #after(&after) ⇒ Object
- #before(&before) ⇒ Object
-
#initialize(method, resource) ⇒ Method
constructor
A new instance of Method.
- #process(*args) ⇒ Object
Constructor Details
#initialize(method, resource) ⇒ Method
Returns a new instance of Method.
5 6 7 8 |
# File 'lib/pillow/method.rb', line 5 def initialize(method, resource) @method = method @resource = resource end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/pillow/method.rb', line 3 def method @method end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
3 4 5 |
# File 'lib/pillow/method.rb', line 3 def resource @resource end |
Instance Method Details
#after(&after) ⇒ Object
15 16 17 18 |
# File 'lib/pillow/method.rb', line 15 def after(&after) @after = after if after @after end |
#before(&before) ⇒ Object
10 11 12 13 |
# File 'lib/pillow/method.rb', line 10 def before(&before) @before = before if before @before end |
#process(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pillow/method.rb', line 20 def process(*args) request = Pillow::Request.new(method, resource.url) request.query_values.replace(resource.query_values) request.headers.replace(resource.headers) before.call(request, *args) if before = {} [:data] = request.raw_body if request.raw_body raw_response = resource.session.request(request.method, request.full_url, request.headers, ) response = Pillow::Response.new response.status = raw_response.status response.headers = raw_response.headers response.raw_body = raw_response.body return after.call(response, *args) if after response end |