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
-
.run(*args) ⇒ Object
Helper method to instantiate a new object and run the server.
Instance Method Summary collapse
-
#initialize ⇒ MachineGun
constructor
A new instance of MachineGun.
-
#run(opts = {}) ⇒ Object
Run the automatically-reloading web server.
-
#running? ⇒ Boolean
True if the server is running.
-
#stop ⇒ Object
Stop watching for file changes and shutdown the web server.
Constructor Details
#initialize ⇒ MachineGun
Returns a new instance of MachineGun.
13 14 15 |
# File 'lib/machinegun.rb', line 13 def initialize @running = false end |
Class Method Details
.run(*args) ⇒ Object
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
#run(opts = {}) ⇒ Object
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 |
#running? ⇒ Boolean
Returns true if the server is running.
45 46 47 |
# File 'lib/machinegun.rb', line 45 def running? @running end |
#stop ⇒ Object
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 |