Class: EmmyHttp::Operation
- Inherits:
-
Object
- Object
- EmmyHttp::Operation
- Defined in:
- lib/emmy_http/operation.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(request, adapter) ⇒ Operation
constructor
A new instance of Operation.
- #serializable_hash ⇒ Object
- #sync ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(request, adapter) ⇒ Operation
Returns a new instance of Operation.
12 13 14 15 16 17 18 |
# File 'lib/emmy_http/operation.rb', line 12 def initialize(request, adapter) @request = request @adapter = adapter @adapter.delegate = self @response = Response.new setup end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/emmy_http/operation.rb', line 7 def adapter @adapter end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/emmy_http/operation.rb', line 8 def connection @connection end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/emmy_http/operation.rb', line 5 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/emmy_http/operation.rb', line 6 def response @response end |
Instance Method Details
#connect ⇒ Object
20 21 22 |
# File 'lib/emmy_http/operation.rb', line 20 def connect @connection ||= EmmyMachine.connect(*self) end |
#serializable_hash ⇒ Object
43 44 45 46 47 48 |
# File 'lib/emmy_http/operation.rb', line 43 def serializable_hash { request: request && request.serializable_hash, response: response && response.serializable_hash } end |
#sync ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/emmy_http/operation.rb', line 24 def sync Fiber.sync do |fiber| # create connection connect on :success do |operation, conn| fiber.resume operation.response end on :error do |error, operation, conn| fiber.leave ConnectionError, error.to_s end end end |
#to_a ⇒ Object
39 40 41 |
# File 'lib/emmy_http/operation.rb', line 39 def to_a adapter.to_a end |