Class: Mxrb::RubyApp::RackAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/ruby_app.rb

Overview

Exposes the same generic MXRB backend through the Rack protocol. Puma, Sinatra and Rails presets mount this adapter instead of duplicating API behavior or introducing a second application state.

Defined Under Namespace

Classes: Request, Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ RackAdapter

Returns a new instance of RackAdapter.



1237
1238
1239
1240
# File 'lib/mxrb/ruby_app.rb', line 1237

def initialize(root)
  @root = File.expand_path(root)
  @server_mutex = Mutex.new
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



1235
1236
1237
# File 'lib/mxrb/ruby_app.rb', line 1235

def root
  @root
end

Instance Method Details

#call(environment) ⇒ Object



1246
1247
1248
1249
1250
1251
# File 'lib/mxrb/ruby_app.rb', line 1246

def call(environment)
  request = rack_request(environment)
  response = Response.new
  server.send(:dispatch, request, response)
  [response.status, response.headers, [response.body.to_s]]
end

#closeObject



1253
# File 'lib/mxrb/ruby_app.rb', line 1253

def close = @server&.application&.close

#serverObject



1242
1243
1244
# File 'lib/mxrb/ruby_app.rb', line 1242

def server
  @server || @server_mutex.synchronize { @server ||= Server.new(root, port: 0) }
end