guard-combustion 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +61 -10
- data/lib/guard/combustion.rb +20 -3
- data/lib/guard/combustion/combustion_helper.rb +166 -99
- data/lib/guard/combustion/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa81a552ad020ab25bdf5848cfdf3f0a570c60a9
|
4
|
+
data.tar.gz: c0af917e393b7133b313ce49cdf66879f37dbee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe00e633279bbb26c8d24e02566874ec11f4d13cf7deaee39480616bb9ab2e2a23646273e90895ee5ae7505c77250a7da82c4e98e8c5d61d8e8c5c8cbde37c5
|
7
|
+
data.tar.gz: bb5bc2580e258362d3c79d0141795e5b63c44873b1316f0b40b6b41437dcfe4d5b706b845ccf11e69223e444c25d5f8de75bd9c94b5c6f6cb13eebdc6d4fa703
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Install the gem with:
|
|
12
12
|
|
13
13
|
Or add it to your Gemfile:
|
14
14
|
|
15
|
-
gem "guard-combustion", "~> 0.
|
15
|
+
gem "guard-combustion", "~> 1.0.0"
|
16
16
|
|
17
17
|
And then add a basic setup to your Guardfile:
|
18
18
|
|
@@ -20,14 +20,63 @@ And then add a basic setup to your Guardfile:
|
|
20
20
|
|
21
21
|
## Configuration
|
22
22
|
|
23
|
-
###
|
23
|
+
### Options
|
24
24
|
|
25
|
-
|
26
|
-
You can choose another port (e.g. 3000) modifying (or creating) the file `/path/to/your/engine/.guard_combustion_port`
|
25
|
+
You can use some options to configure guard-combustion from the Guardfile.
|
27
26
|
|
28
|
-
|
27
|
+
#### Port
|
29
28
|
|
30
|
-
|
29
|
+
Combustion listens by default on the port 9292. To change the port, use the `:port` option. E.g.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
guard :combustion, port: 3000 do
|
33
|
+
watch(%r{^(app|config|lib|spec)/(.*)})
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Pid File
|
38
|
+
|
39
|
+
Guard::Combustion saves the PID of Combustion into a file when it has been just created, and deletes it when Combustion stops.
|
40
|
+
|
41
|
+
By default, the pid file is `./tmp/.combustion_pid`, but if you want to change the path, you can set the `:pid_file` option (make sure that the path already exists, or create the required directories).
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
guard :combustion, pid_file: './my_dir/my_new_pid_file.example' do
|
45
|
+
watch(%r{^(app|config|lib|spec)/(.*)})
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Colors
|
50
|
+
|
51
|
+
If you want to turn off the colored prints, set the `:color` option to `false`
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
guard :combustion, color: false do
|
55
|
+
watch(%r{^(app|config|lib|spec)/(.*)})
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
#### Custom Port File
|
60
|
+
|
61
|
+
The `:port` option mentioned above is a perfect solution if you are working alone, or with people that all want to use the same listening port.
|
62
|
+
|
63
|
+
But... what if you want to use a different port from your team mates?
|
64
|
+
|
65
|
+
No worries: you can set your custom port by writing it (and only it!) into the file `.guard_combustion_port` at the root of your project. This file has major priority than the port set into the Guardfile.
|
66
|
+
|
67
|
+
.guard_combustion_port file: E.g.
|
68
|
+
|
69
|
+
8080
|
70
|
+
|
71
|
+
If you add `.guard_combustion_port` to the `.gitignore` file, your team mates won't even notice the difference.
|
72
|
+
|
73
|
+
If you don't like to add files at the root of your project, you can also change the custom port file, setting the `:custom_port_file` option.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
guard :combustion, custom_port_file: "my_new_custom_port_file.example" do
|
77
|
+
watch(%r{^(app|config|lib|spec)/(.*)})
|
78
|
+
end
|
79
|
+
```
|
31
80
|
|
32
81
|
### Integration with guard-rspec (or any other guard)
|
33
82
|
|
@@ -37,9 +86,11 @@ to avoid conflicts with the instance of Combustion created by Rspec.
|
|
37
86
|
|
38
87
|
For doing that, you have to add theese lines into the `guard :rspec` block
|
39
88
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
89
|
+
```ruby
|
90
|
+
callback(:run_all_begin) { Guard::CombustionHelper.stop_combustion }
|
91
|
+
callback(:run_on_modifications_begin) { Guard::CombustionHelper.stop_combustion }
|
92
|
+
callback(:run_all_end) { Guard::CombustionHelper.start_combustion }
|
93
|
+
callback(:run_on_modifications_end) { Guard::CombustionHelper.start_combustion }
|
94
|
+
```
|
44
95
|
|
45
96
|
For more informations about callbacks, see https://github.com/guard/guard/wiki/Hooks-and-callbacks
|
data/lib/guard/combustion.rb
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
require 'guard'
|
2
|
-
require 'guard/
|
2
|
+
require 'guard/plugin'
|
3
3
|
require 'guard/combustion/version'
|
4
4
|
require 'guard/combustion/combustion_helper'
|
5
5
|
|
6
|
+
#
|
7
|
+
# The guard module
|
8
|
+
#
|
9
|
+
# @author [chosko]
|
10
|
+
#
|
6
11
|
module Guard
|
7
|
-
|
8
|
-
|
12
|
+
|
13
|
+
#
|
14
|
+
# The Guard::Combustion class
|
15
|
+
#
|
16
|
+
# @author [chosko]
|
17
|
+
#
|
18
|
+
class Combustion < Plugin
|
19
|
+
|
20
|
+
def initialize (options = {})
|
21
|
+
super
|
22
|
+
CombustionHelper.set_options(options)
|
23
|
+
end
|
24
|
+
|
9
25
|
def start
|
26
|
+
::Guard::UI.info "Guard::Combustion is running"
|
10
27
|
CombustionHelper.start_combustion
|
11
28
|
end
|
12
29
|
|
@@ -1,129 +1,196 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
1
|
+
module Guard
|
2
|
+
#
|
3
|
+
# This class contains some useful functions to automatically manage the interaction between combustion and guard.
|
4
|
+
#
|
5
|
+
# @author [chosko]
|
6
|
+
#
|
7
|
+
class CombustionHelper
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
#
|
10
|
+
# Default options
|
11
|
+
#
|
12
|
+
DEFAULTS = {
|
13
|
+
# The listening port of combustion
|
14
|
+
port: 9292,
|
15
|
+
|
16
|
+
# The file where is stored the pid of combustion
|
17
|
+
pid_file: "./tmp/.combustion_pid",
|
18
|
+
|
19
|
+
# The file where is stored the port used by combustion
|
20
|
+
custom_port_file: ".guard_combustion_port",
|
21
|
+
|
22
|
+
# Coloured prints
|
23
|
+
colors: true
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
#
|
27
|
+
# The options for combustion
|
28
|
+
#
|
29
|
+
@@options = DEFAULTS
|
10
30
|
|
11
|
-
class << self
|
12
31
|
#
|
13
|
-
#
|
32
|
+
# This variable records the last time that combustion was started
|
14
33
|
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
34
|
+
@@last_start = Time.now - 5
|
35
|
+
|
36
|
+
class << self
|
37
|
+
#
|
38
|
+
# Set the options for combustion
|
39
|
+
#
|
40
|
+
def set_options(options = {})
|
41
|
+
@@options = _deep_merge(DEFAULTS, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Start combustion
|
46
|
+
#
|
47
|
+
def start_combustion
|
22
48
|
pid = get_combustion_pid
|
23
49
|
if pid.nil?
|
24
|
-
|
50
|
+
::Guard::UI.info "Starting combustion..."
|
51
|
+
combustion_port = get_guard_combustion_port
|
52
|
+
`#{combustion_cmd(combustion_port)}`
|
53
|
+
sleep(1)
|
54
|
+
@@last_start = Time.now
|
55
|
+
pid = get_combustion_pid
|
56
|
+
if pid.nil?
|
57
|
+
::Guard::UI.error "Something went wrong, likely Combustion was not started"
|
58
|
+
else
|
59
|
+
::Guard::UI.info strcolor("Combustion started with pid #{pid} and listening on port #{combustion_port}", "green")
|
60
|
+
end
|
25
61
|
else
|
26
|
-
|
62
|
+
::Guard::UI.warning "Another instance of Combustion is already running with pid #{pid}"
|
63
|
+
restart_combustion
|
27
64
|
end
|
28
|
-
else
|
29
|
-
puts "another instance of combustion is already running with pid #{pid}"
|
30
|
-
restart_combustion
|
31
65
|
end
|
32
|
-
end
|
33
66
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
67
|
+
#
|
68
|
+
# Stop combustion
|
69
|
+
#
|
70
|
+
def stop_combustion
|
71
|
+
::Guard::UI.info "Stopping combustion..."
|
72
|
+
pid = get_combustion_pid
|
73
|
+
if pid.nil?
|
74
|
+
::Guard::UI.warning "No instances of combustion were found"
|
75
|
+
else
|
76
|
+
`kill -9 #{pid}`
|
77
|
+
::Guard::UI.info strcolor("Combustion stopped", "red")
|
78
|
+
delete_combustion_pid
|
79
|
+
end
|
46
80
|
end
|
47
|
-
end
|
48
81
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
82
|
+
#
|
83
|
+
# Restart combustion
|
84
|
+
#
|
85
|
+
def restart_combustion
|
86
|
+
if Time.now > @@last_start + 1 # Check if the server started less than a second ago
|
87
|
+
::Guard::UI.info "Restarting combustion..."
|
88
|
+
stop_combustion
|
89
|
+
start_combustion
|
90
|
+
end
|
57
91
|
end
|
58
|
-
end
|
59
92
|
|
60
|
-
|
93
|
+
private
|
61
94
|
|
62
|
-
#
|
63
|
-
# Write the port that will be used by combustion into .guard_combustion_port
|
64
|
-
#
|
65
|
-
def set_guard_combustion_port
|
66
|
-
file = File.open(@@guard_combustion_port, "w")
|
67
|
-
file.write(@@default_port.to_s)
|
68
|
-
file.close
|
69
|
-
@@default_port
|
70
|
-
end
|
71
95
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
96
|
+
#
|
97
|
+
# Make a string colored
|
98
|
+
# @param string [String] The string to make colored
|
99
|
+
# @param color=nil [String] The name of the color (e.g. 'yellow')
|
100
|
+
#
|
101
|
+
# @return [String] the input string colored
|
102
|
+
def strcolor(string, color=nil)
|
103
|
+
return string if !@@options[:colors] || color.nil?
|
104
|
+
|
105
|
+
case color
|
106
|
+
when "green"
|
107
|
+
"\033[22;32m#{string}\x1b[0m"
|
108
|
+
when "red"
|
109
|
+
"\033[22;31m#{string}\x1b[0m"
|
110
|
+
when "yellow"
|
111
|
+
"\033[01;33m#{string}\x1b[0m"
|
84
112
|
else
|
85
|
-
|
113
|
+
string
|
86
114
|
end
|
87
|
-
rescue ArgumentError => e
|
88
|
-
file.close
|
89
|
-
set_guard_combustion_port
|
90
115
|
end
|
91
|
-
end
|
92
116
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
117
|
+
#
|
118
|
+
# Recursively merge two hashes, with major priority for the second hash
|
119
|
+
# @param hash1 [Hash] The first hash
|
120
|
+
# @param hash2 [Hash] The second hash
|
121
|
+
#
|
122
|
+
# @return [Hash] The merged hash
|
123
|
+
def _deep_merge(hash1, hash2)
|
124
|
+
hash1.merge(hash2) do |key, oldval, newval|
|
125
|
+
if oldval.instance_of?(Hash) && newval.instance_of?(Hash)
|
126
|
+
_deep_merge(oldval, newval)
|
127
|
+
else
|
128
|
+
newval
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Read the port from .guard_combustion_port, if the file exists.
|
135
|
+
#
|
136
|
+
# Else, use the port configured by option, or the default port.
|
137
|
+
#
|
138
|
+
def get_guard_combustion_port
|
139
|
+
begin
|
140
|
+
if File.exists? @@options[:custom_port_file]
|
141
|
+
file = File.open(@@options[:custom_port_file], "r")
|
142
|
+
contents = file.read
|
143
|
+
combustion_port = Integer(contents.split("\n")[0])
|
144
|
+
file.close
|
145
|
+
::Guard::UI.info "Custom port configuration file detected at #{@@options[:custom_port_file]} - Using port #{combustion_port} instead of #{@@options[:port]}."
|
146
|
+
::Guard::UI.info "If you want to use the port defined into the Guardfile, please remove #{@@options[:custom_port_file]}"
|
147
|
+
combustion_port
|
148
|
+
else
|
149
|
+
@@options[:port]
|
150
|
+
end
|
151
|
+
rescue ArgumentError => e
|
152
|
+
file.close
|
153
|
+
::Guard::UI.error "Failed to load custom port from " + @@options[:custom_port_file] + ", because it contains non-integer value."
|
154
|
+
::Guard::UI.warning "Using the default port: " + @@options[:port].to_s
|
155
|
+
@@options[:port]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# Read combustion's pid from .combustion_pid
|
161
|
+
#
|
162
|
+
def get_combustion_pid
|
163
|
+
begin
|
164
|
+
if File.exists? @@options[:pid_file]
|
165
|
+
file = File.open(@@options[:pid_file], "r")
|
166
|
+
contents = file.read
|
167
|
+
combustion_pid = Integer(contents.split("\n")[0])
|
168
|
+
file.close
|
169
|
+
combustion_pid
|
170
|
+
else
|
171
|
+
nil
|
172
|
+
end
|
173
|
+
rescue ArgumentError => e
|
102
174
|
file.close
|
103
|
-
combustion_pid
|
104
|
-
else
|
105
175
|
nil
|
106
176
|
end
|
107
|
-
rescue ArgumentError => e
|
108
|
-
file.close
|
109
|
-
nil
|
110
177
|
end
|
111
|
-
end
|
112
178
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
179
|
+
#
|
180
|
+
# Delete .combustion_pid
|
181
|
+
#
|
182
|
+
def delete_combustion_pid
|
183
|
+
if File.exists? @@options[:pid_file]
|
184
|
+
File.delete(@@options[:pid_file])
|
185
|
+
end
|
119
186
|
end
|
120
|
-
end
|
121
187
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
188
|
+
#
|
189
|
+
# Return a string with the shell command used for starting combustion
|
190
|
+
#
|
191
|
+
def combustion_cmd combustion_port
|
192
|
+
"rackup -p #{combustion_port} -D -P #{@@options[:pid_file]}"
|
193
|
+
end
|
127
194
|
end
|
128
195
|
end
|
129
196
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-combustion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruben Caliandro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -63,3 +63,4 @@ signing_key:
|
|
63
63
|
specification_version: 4
|
64
64
|
summary: Guard gem for running Combustion
|
65
65
|
test_files: []
|
66
|
+
has_rdoc:
|