Class: Hourglass::Runner
- Inherits:
-
Object
- Object
- Hourglass::Runner
- Defined in:
- lib/hourglass/runner.rb
Defined Under Namespace
Classes: BrowserWrapper, ShellWrapper
Instance Method Summary collapse
-
#initialize(argv = ARGV) ⇒ Runner
constructor
A new instance of Runner.
- #start_browser ⇒ Object
- #start_server ⇒ Object
Constructor Details
#initialize(argv = ARGV) ⇒ Runner
Returns a new instance of Runner.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/hourglass/runner.rb', line 132 def initialize(argv = ARGV) = {} OptionParser.new do |opts| opts. = "Usage: #{$0} [options]" opts.on("-s", "--server-only", "Only run the web server") do |s| ['server_only'] = s end end.parse(argv) Database.migrate! if start_server if ['server_only'] @web_thread.join else start_browser end end Activity.stop_current_activities end |
Instance Method Details
#start_browser ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/hourglass/runner.rb', line 169 def start_browser display = Swt::Widgets::Display.new shell_wrapper = ShellWrapper.new(display, 'name' => 'main') browser_wrapper = BrowserWrapper.new(shell_wrapper) browser_wrapper.set_url("http://localhost:4567", nil, ["user-agent: SWT"].to_java(:String)) shell_wrapper.open while !shell_wrapper.disposed? if !display.read_and_dispatch display.sleep end end display.dispose end |
#start_server ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/hourglass/runner.rb', line 153 def start_server handler = Rack::Handler.get('mongrel') settings = Application.settings @web_server = Mongrel::HttpServer.new(settings.bind, settings.port, 950, 0, 60) @web_server.register('/', handler.new(Application)) success = false begin @web_thread = @web_server.run success = true rescue Errno::EADDRINUSE => e puts "Can't start web server, port already in use. Aborting..." end success end |