Class: ActiveRpc::RackServer
- Inherits:
-
Object
- Object
- ActiveRpc::RackServer
- Defined in:
- lib/active_rpc/rack_server.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(request) ⇒ RackServer
constructor
A new instance of RackServer.
Constructor Details
#initialize(request) ⇒ RackServer
Returns a new instance of RackServer.
9 10 11 |
# File 'lib/active_rpc/rack_server.rb', line 9 def initialize(request) @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/active_rpc/rack_server.rb', line 7 def request @request end |
Class Method Details
.call(env) ⇒ Object
3 4 5 |
# File 'lib/active_rpc/rack_server.rb', line 3 def self.call(env) new(Rack::Request.new(env)).call end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_rpc/rack_server.rb', line 13 def call res = nil begin res = case body when Array then body.map(&method(:process_item)).map(&:to_hash) when Hash then process_item(body).to_hash end rescue JSON::ParserError => ex res = ActiveRpc::Response.new do |r| r.error = Errors::ParseError.new(message: ex.to_s) end.to_hash end [ 200, {'Content-Type' => 'application/json'}, [JSON.generate(res)] ] end |