Class: Guard::Falcon::Controller
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Falcon::Controller
- Defined in:
- lib/guard/falcon/controller.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ config: 'config.ru', concurrency: 2, verbose: false, }
Instance Method Summary collapse
- #endpoint ⇒ Object
-
#initialize(**options) ⇒ Controller
constructor
A new instance of Controller.
-
#logger ⇒ Object
As discussed in github.com/guard/guard/issues/713.
- #reload ⇒ Object
- #run_on_change(paths) ⇒ Object
- #run_server ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(**options) ⇒ Controller
Returns a new instance of Controller.
44 45 46 47 48 49 50 |
# File 'lib/guard/falcon/controller.rb', line 44 def initialize(**) super @options = DEFAULT_OPTIONS.merge() @endpoint = nil @container = nil end |
Instance Method Details
#endpoint ⇒ Object
69 70 71 |
# File 'lib/guard/falcon/controller.rb', line 69 def endpoint @endpoint ||= build_endpoint end |
#logger ⇒ Object
As discussed in github.com/guard/guard/issues/713
53 54 55 |
# File 'lib/guard/falcon/controller.rb', line 53 def logger Compat::UI end |
#reload ⇒ Object
109 110 111 112 |
# File 'lib/guard/falcon/controller.rb', line 109 def reload stop start end |
#run_on_change(paths) ⇒ Object
121 122 123 |
# File 'lib/guard/falcon/controller.rb', line 121 def run_on_change(paths) reload end |
#run_server ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/guard/falcon/controller.rb', line 73 def run_server shared_endpoint = Async::Reactor.run do Async::IO::SharedEndpoint.bound(endpoint) end.result logger.info("Starting Falcon HTTP server on #{endpoint}.") container = Async::Container::Forked.new(concurrency: @options[:concurrency]) do begin rack_app, = Rack::Builder.parse_file(@options[:config]) rescue logger.error "Failed to load #{@options[:config]}: #{$!}" logger.error $!.backtrace end app = ::Falcon::Server.middleware(rack_app, verbose: @options[:verbose]) server = ::Falcon::Server.new(app, shared_endpoint, endpoint.protocol, endpoint.scheme) Process.setproctitle "Guard::Falcon HTTP Server: #{endpoint}" server.run end shared_endpoint.close return container end |
#running? ⇒ Boolean
105 106 107 |
# File 'lib/guard/falcon/controller.rb', line 105 def running? !@container.nil? end |
#start ⇒ Object
101 102 103 |
# File 'lib/guard/falcon/controller.rb', line 101 def start @container = run_server end |
#stop ⇒ Object
114 115 116 117 118 119 |
# File 'lib/guard/falcon/controller.rb', line 114 def stop if @container @container.stop @container = nil end end |