Class: RazyK::Application
- Inherits:
-
Object
- Object
- RazyK::Application
- Defined in:
- lib/razyk/application.rb
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #run(argv) ⇒ Object
- #run_interpreter(argv) ⇒ Object
- #run_web_server ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 16 |
# File 'lib/razyk/application.rb', line 11 def initialize @program = nil @step = false @web_server = false @optparse = option_parser end |
Instance Method Details
#run(argv) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/razyk/application.rb', line 96 def run(argv) @optparse.parse!(argv) if @web_server run_web_server else run_interpreter(argv) end rescue RazyK::ApplicationError $stderr.puts($!.) end |
#run_interpreter(argv) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/razyk/application.rb', line 64 def run_interpreter(argv) if @program.nil? if argv.empty? raise RazyK::ApplicationError, "please specify LazyK program file" end filepath = argv.shift unless File.readable?(filepath) raise RazyK::ApplicationError, "#{filepath} not found or not readable" end @program = IO.read(filepath) end opts = { statistics: @statistics, audio: @audio, } if @step RazyK.run(@program, opts) do |vm| $stderr.puts vm.tree.inspect end else RazyK.run(@program, opts) end ensure if @statistics puts "Statistics Info:" puts "\t#{@statistics[:started_at]} - #{@statistics[:finished_at]} (#{@statistics[:finished_at]-@statistics[:started_at]} sec)" puts "\treduce count: #{@statistics[:count]}" end end |
#run_web_server ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/razyk/application.rb', line 49 def run_web_server require "razyk/webapp" app = RazyK::WebApp.new # This should work, but rack-1.2.1 fails. :app don't overwrite config.ru #Rack::Server.start(:app => app, :Port => @port) trap(:INT) do if Rack::Handler::WEBrick.respond_to?(:shutdown) Rack::Handler::WEBrick.shutdown else exit end end Rack::Handler::WEBrick.run(app, :Port => @port) end |