Class: JSONRPC::BatchResponse
- Inherits:
-
Object
- Object
- JSONRPC::BatchResponse
- Includes:
- Enumerable
- Defined in:
- lib/jsonrpc/batch_response.rb
Overview
A JSON-RPC 2.0 Batch Response object
A Batch Response is an Array containing Response objects, corresponding to a Batch Request. The Server should respond with one Response for each Request (except for Notifications which don’t receive responses).
Instance Attribute Summary collapse
-
#responses ⇒ Array<JSONRPC::Response>
readonly
The collection of response objects in this batch.
Instance Method Summary collapse
-
#each {|response| ... } ⇒ Enumerator, BatchResponse
Implements the Enumerable contract by yielding each response in the batch.
-
#initialize(responses) ⇒ BatchResponse
constructor
Creates a new JSON-RPC 2.0 Batch Response object.
-
#to_h ⇒ Array<Hash>
Converts the batch response to a JSON-compatible Array.
-
#to_json ⇒ String
Converts the batch response to a JSON string.
-
#to_response ⇒ Array
Converts the batch response to a response format.
Constructor Details
#initialize(responses) ⇒ BatchResponse
Creates a new JSON-RPC 2.0 Batch Response object
50 51 52 53 |
# File 'lib/jsonrpc/batch_response.rb', line 50 def initialize(responses) validate_responses(responses) @responses = responses end |
Instance Attribute Details
#responses ⇒ Array<JSONRPC::Response> (readonly)
The collection of response objects in this batch
29 30 31 |
# File 'lib/jsonrpc/batch_response.rb', line 29 def responses @responses end |
Instance Method Details
#each {|response| ... } ⇒ Enumerator, BatchResponse
Implements the Enumerable contract by yielding each response in the batch
96 97 98 99 100 101 |
# File 'lib/jsonrpc/batch_response.rb', line 96 def each(&) return to_enum(:each) unless block_given? responses.each(&) self end |
#to_h ⇒ Array<Hash>
Converts the batch response to a JSON-compatible Array
64 65 66 |
# File 'lib/jsonrpc/batch_response.rb', line 64 def to_h responses.map(&:to_h) end |
#to_json ⇒ String
Converts the batch response to a JSON string
77 78 79 |
# File 'lib/jsonrpc/batch_response.rb', line 77 def to_json(*) MultiJson.dump(to_h, *) end |
#to_response ⇒ Array
Converts the batch response to a response format
112 113 114 |
# File 'lib/jsonrpc/batch_response.rb', line 112 def to_response responses.map(&:to_response) end |