Class: MachineGun
- Inherits:
-
Object
- Object
- MachineGun
- Defined in:
- lib/machinegun.rb
Overview
An automatic reloading Rack development web server for Ruby.
Class Method Summary (collapse)
-
+ (Object) run(*args)
Helper method to instantiate a new object and run the server.
Instance Method Summary (collapse)
-
- (MachineGun) initialize
constructor
A new instance of MachineGun.
-
- (Object) run(opts = {})
Run the automatically-reloading web server.
-
- (Boolean) running?
True if the server is running.
-
- (Object) stop
Stop watching for file changes and shutdown the web server.
Constructor Details
- (MachineGun) initialize
Returns a new instance of MachineGun
13 14 15 |
# File 'lib/machinegun.rb', line 13 def initialize @running = false end |
Class Method Details
+ (Object) run(*args)
Helper method to instantiate a new object and run the server.
9 10 11 |
# File 'lib/machinegun.rb', line 9 def self.run *args new.run *args end |
Instance Method Details
- (Object) run(opts = {})
Run the automatically-reloading web server. This method blocks.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/machinegun.rb', line 21 def run opts = {} @running = true interval = opts[:interval] || 0.5 @pid = start_server @watcher = FileWatcher.new("./**/*.rb") @watcher.watch interval do stop_server @pid = start_server end end |
- (Boolean) running?
Returns true if the server is running.
45 46 47 |
# File 'lib/machinegun.rb', line 45 def running? @running end |
- (Object) stop
Stop watching for file changes and shutdown the web server.
36 37 38 39 40 41 42 |
# File 'lib/machinegun.rb', line 36 def stop return unless @running @watcher.stop stop_server @running = false end |