guard-falcon 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c50d55e76713e7b5e3117b2ad4afc08e9dc69f85
4
- data.tar.gz: b2f9733ddfbbd33884cc5c254d6bb1e2812fcc6f
3
+ metadata.gz: ca8f7786cc49b12b390f9dc881dd08bb17c11a52
4
+ data.tar.gz: bc9e3180f55c5ccd22f7ebf1324983c1832cbd51
5
5
  SHA512:
6
- metadata.gz: b4e37e32a0e16ce8023525e0641e47f98cad4e99655a3fdc013abcde5208d714937ab4b6853b20d9d488a5dcdf0a611ef8b87aced6728e8dc16462dca563e0f8
7
- data.tar.gz: 262ec584d5bd5cb43b4fcc65a97456a9a894b6933c0a6c0dcc4ddf1695c266da3d289902ceaa8327cc6ebbb567a1657259b1c02324e5010bc11b1220d51f09ed
6
+ metadata.gz: 68b790dc399be8fa42a53543b196f786c14a75b100a86fbd4599bec61cda6931f05dbf7e874d7d5ca440d8e3c70d9492f4120b16a2918180db6b91f555e08e35
7
+ data.tar.gz: b3f5b549ebc6bd313a6c0795cee8398e8d1427f75cb20de9b59126fb0a8d8991bc95bfbd410ee3a6d48e103eba8971883922170b775a2b8f516cec9caffe1359
@@ -18,68 +18,17 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'guard/compat/plugin'
22
-
23
- require 'rack/builder'
24
- require 'rack/server'
25
-
26
- require 'async/container'
27
- require "falcon/server"
21
+ require_relative 'falcon/controller'
28
22
 
29
23
  module Guard
30
- class Falcon < Plugin
31
- attr_reader :options, :runner
32
-
33
- def self.default_env
34
- ENV.fetch('RACK_ENV', 'development')
35
- end
36
-
37
- DEFAULT_OPTIONS = {
38
- :bind => "tcp://localhost:9000",
39
- :environment => default_env,
40
- :config => 'config.ru',
41
- }
42
-
43
- def initialize(**options)
44
- super
45
-
46
- @options = DEFAULT_OPTIONS.merge(options)
47
- @container = nil
48
- end
49
-
50
- def run_server
51
- app, options = Rack::Builder.parse_file(@options[:config])
52
-
53
- UI.info("Starting HTTP server on #{@options[:bind]}.")
54
-
55
- Async::Container::Threaded.new(concurrency: 2) do
56
- server = ::Falcon::Server.new(app, [
57
- Async::IO::Address.parse(@options[:bind], reuse_port: true)
58
- ])
59
-
60
- server.run
61
- end
62
- rescue
63
-
64
- return nil
24
+ module Falcon
25
+ def self.new(*args)
26
+ Controller.new(*args)
65
27
  end
66
-
67
- def start
68
- @container = run_server
69
- end
70
-
71
- def reload
72
- stop
73
- start
74
- end
75
-
76
- def stop
77
- @container.stop
78
- @container = nil
79
- end
80
-
81
- def run_on_change(paths)
82
- reload
28
+
29
+ # Workaround for https://github.com/guard/guard/pull/872
30
+ def self.superclass
31
+ nil
83
32
  end
84
33
  end
85
34
  end
@@ -0,0 +1,100 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'guard/compat/plugin'
22
+
23
+ require 'rack/builder'
24
+ require 'rack/server'
25
+
26
+ require 'async/container/forked'
27
+ require 'falcon/server'
28
+
29
+ module Guard
30
+ module Falcon
31
+ class Controller < Plugin
32
+ def self.default_env
33
+ ENV.fetch('RACK_ENV', 'development')
34
+ end
35
+
36
+ DEFAULT_OPTIONS = {
37
+ :bind => "tcp://localhost:9000",
38
+ :environment => default_env,
39
+ :config => 'config.ru',
40
+ }
41
+
42
+ def initialize(**options)
43
+ super
44
+
45
+ @options = DEFAULT_OPTIONS.merge(options)
46
+ @container = nil
47
+ end
48
+
49
+ # As discussed in https://github.com/guard/guard/issues/713
50
+ def logger
51
+ Compat::UI
52
+ end
53
+
54
+ def run_server
55
+ begin
56
+ app, options = Rack::Builder.parse_file(@options[:config])
57
+ rescue
58
+ logger.error "Failed to load #{@options[:config]}: #{$!}"
59
+ logger.error $!.backtrace
60
+ end
61
+
62
+ logger.info("Starting Falcon HTTP server on #{@options[:bind]}.")
63
+
64
+ Async::Container::Forked.new(concurrency: 2) do
65
+ server = ::Falcon::Server.new(app, [
66
+ Async::IO::Address.parse(@options[:bind], reuse_port: true)
67
+ ])
68
+
69
+ Process.setproctitle "Falcon HTTP #{@options[:bind]}"
70
+
71
+ server.run
72
+ end
73
+ end
74
+
75
+ def start
76
+ @container = run_server
77
+ end
78
+
79
+ def running?
80
+ !@container.nil?
81
+ end
82
+
83
+ def reload
84
+ stop
85
+ start
86
+ end
87
+
88
+ def stop
89
+ if @container
90
+ @container.stop
91
+ @container = nil
92
+ end
93
+ end
94
+
95
+ def run_on_change(paths)
96
+ reload
97
+ end
98
+ end
99
+ end
100
+ end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Guard
22
22
  module Falcon
23
- VERSION = "0.1.0"
23
+ VERSION = "0.2.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-falcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -109,6 +109,7 @@ files:
109
109
  - Rakefile
110
110
  - guard-falcon.gemspec
111
111
  - lib/guard/falcon.rb
112
+ - lib/guard/falcon/controller.rb
112
113
  - lib/guard/falcon/templates/Guardfile
113
114
  - lib/guard/falcon/version.rb
114
115
  homepage: https://github.com/socketry/guard-falcon