Class: Opal::CliRunners::Server
- Inherits:
-
Object
- Object
- Opal::CliRunners::Server
- Defined in:
- opal/lib/opal/cli_runners/server.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #app(source) ⇒ Object
- #exit_status ⇒ Object
-
#initialize(options) ⇒ Server
constructor
A new instance of Server.
- #run(source, argv) ⇒ Object
Constructor Details
#initialize(options) ⇒ Server
Returns a new instance of Server
6 7 8 9 |
# File 'opal/lib/opal/cli_runners/server.rb', line 6 def initialize() @output = .fetch(:output, $stdout) @port = .fetch(:port, 3000).to_int end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output
10 11 12 |
# File 'opal/lib/opal/cli_runners/server.rb', line 10 def output @output end |
#port ⇒ Object (readonly)
Returns the value of attribute port
10 11 12 |
# File 'opal/lib/opal/cli_runners/server.rb', line 10 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server
10 11 12 |
# File 'opal/lib/opal/cli_runners/server.rb', line 10 def server @server end |
Instance Method Details
#app(source) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'opal/lib/opal/cli_runners/server.rb', line 33 def app(source) lambda do |env| case env['PATH_INFO'] when '/' body = <<-HTML <!doctype html> <html> <head> <meta charset="utf-8"/> <script src="/cli_runner.js"></script> </head> </html> HTML [200, {}, [body]] when '/cli_runner.js' [200, {'Content-Type' => 'text/javascript'}, [source]] else [404, {}, [body]] end end end |
#exit_status ⇒ Object
29 30 31 |
# File 'opal/lib/opal/cli_runners/server.rb', line 29 def exit_status nil end |
#run(source, argv) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'opal/lib/opal/cli_runners/server.rb', line 12 def run(source, argv) unless argv.empty? raise ArgumentError, 'Program arguments are not supported on the Server runner' end require 'rack' require 'webrick' require 'logger' @server = Rack::Server.start( :app => app(source), :Port => port, :AccessLog => [], :Logger => Logger.new(output) ) end |