Class: Brief::Server
- Inherits:
-
Object
- Object
- Brief::Server
- Defined in:
- lib/brief/server.rb,
lib/brief/server/socket.rb
Defined Under Namespace
Modules: Handlers Classes: Gateway, Route, Socket
Instance Attribute Summary collapse
-
#briefcase ⇒ Object
readonly
Returns the value of attribute briefcase.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(briefcase, options = {}) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(briefcase, options = {}) ⇒ Server
Returns a new instance of Server.
4 5 6 7 |
# File 'lib/brief/server.rb', line 4 def initialize(briefcase, ={}) @briefcase = briefcase @options = end |
Instance Attribute Details
#briefcase ⇒ Object (readonly)
Returns the value of attribute briefcase.
2 3 4 |
# File 'lib/brief/server.rb', line 2 def briefcase @briefcase end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/brief/server.rb', line 2 def @options end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/brief/server.rb', line 9 def call(env) request = Brief::Server::Route.new(env, briefcase, ) status, headers, body = request.respond() body = body.to_json if body.is_a?(Hash) body = body.to_json if body.is_a?(Array) body = body.as_json.to_json if body.is_a?(Brief::Model) body = "" if body.nil? headers["Content-Length"] = Rack::Utils.bytesize(body).to_s headers["Access-Control-Allow-Origin"] = "*" headers["Access-Control-Allow-Methods"] = "GET, POST, PUT" headers["X-BRIEF-HANDLER"] = request.send(:handler).try(:to_s) [status, headers, [body]] end |