guard-process 1.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE +19 -0
- data/README.md +59 -0
- data/Rakefile +9 -0
- data/guard-process.gemspec +28 -0
- data/lib/guard/process.rb +55 -0
- data/lib/guard/process/templates/Guardfile +5 -0
- data/test/guard/process_test.rb +50 -0
- data/test/run_me.rb +5 -0
- data/test/test_helper.rb +4 -0
- metadata +139 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard 'bundler' do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard 'minitest' do
|
7
|
+
# with Minitest::Unit
|
8
|
+
watch(%r|^test/(.*)_test\.rb|)
|
9
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
|
10
|
+
watch(%r|^test/test_helper\.rb|) { "test" }
|
11
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by SocialReferral
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Guard::Process
|
2
|
+
==============
|
3
|
+
Guard to run continues processes.
|
4
|
+
|
5
|
+
This gem requires Ruby 1.9.2 or JRuby in 1.9 mode.
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
Please read the [Guard documentation](https://github.com/guard/guard#readme) to learn how to use Guard.
|
10
|
+
|
11
|
+
There is also an exellent screencast available on [Railscasts](http://railscasts.com/episodes/264-guard)
|
12
|
+
|
13
|
+
Guardfile
|
14
|
+
---------
|
15
|
+
You can add as many process Guards as you want, an example Guardfile:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
guard 'process', :name => 'EndlessRunner', :command => 'rails runner Something::ThatGoesOnAndOn' do
|
19
|
+
watch('Gemfile.lock')
|
20
|
+
end
|
21
|
+
|
22
|
+
guard 'process', :name => 'AnotherRunner', :command => 'rails runner AnotherRunner' do
|
23
|
+
watch('Gemfile.lock')
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Options
|
28
|
+
-------
|
29
|
+
The following options are available:
|
30
|
+
|
31
|
+
- name
|
32
|
+
The display name of your process in Guard, this is shown when Guard::Process is starting and stopping your process
|
33
|
+
- command
|
34
|
+
The command to run as you would run it from the command line
|
35
|
+
- stop_signal
|
36
|
+
The signal that Guard::Process sends to terminate the process when it needs to stop/restart it. This defaults to 'TERM' (in some cases you may need KILL).
|
37
|
+
- env
|
38
|
+
A Hash with environmental variables to set for the context where your command runs, like so:
|
39
|
+
``` ruby
|
40
|
+
{"SSL_CERTS_DIR" => "/etc/ssl/certs", "JAVA_HOME" => "/usr/local/java"}
|
41
|
+
```
|
42
|
+
|
43
|
+
Development
|
44
|
+
-----------
|
45
|
+
- Source hosted on [GitHub](https://github.com)
|
46
|
+
- Please report issues and feature requests using [GitHub issues](https://github.com/socialreferral/guard-process/issues)
|
47
|
+
|
48
|
+
Pull requests are welcome, please make sure your patches are well tested before contributing. When sending a pull request:
|
49
|
+
- Use a topic branch for your change
|
50
|
+
- Add tests for your changes using MiniTest::Unit
|
51
|
+
- Do not change the version number in the gemspec
|
52
|
+
|
53
|
+
License
|
54
|
+
-------
|
55
|
+
Guard::Process is released under the MIT license.
|
56
|
+
|
57
|
+
Author
|
58
|
+
------
|
59
|
+
[Mark Kremer](https://github.com/mkremer)
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'rbconfig' unless defined?(RbConfig)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "guard-process"
|
7
|
+
s.version = "1.0"
|
8
|
+
s.authors = ["Mark Kremer"]
|
9
|
+
s.email = ["mark@socialreferral.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Guard extension to run cli processes}
|
12
|
+
s.description = %q{Guard extension to run cli processes}
|
13
|
+
|
14
|
+
s.required_ruby_version = '~> 1.9.2'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('guard', '>= 0.4.2')
|
22
|
+
s.add_development_dependency('minitest')
|
23
|
+
s.add_development_dependency('mocha')
|
24
|
+
s.add_development_dependency('guard-minitest')
|
25
|
+
s.add_development_dependency('guard-bundler')
|
26
|
+
s.add_development_dependency('rake')
|
27
|
+
s.add_development_dependency('rb-inotify') if RbConfig::CONFIG['target_os'] == 'linux'
|
28
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
|
4
|
+
module Guard
|
5
|
+
class Process < Guard
|
6
|
+
def initialize(watchers = [], options = {})
|
7
|
+
@process = nil
|
8
|
+
@pid = nil
|
9
|
+
@command = options[:command]
|
10
|
+
@env = options[:env]
|
11
|
+
@name = options[:name]
|
12
|
+
@stop_signal = options[:stop_signal] || "TERM"
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_running?
|
17
|
+
begin
|
18
|
+
@pid ? ::Process.kill(0, @pid) : false
|
19
|
+
rescue Errno::ESRCH => e
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
UI.info("Starting process #{@name}")
|
26
|
+
@process = @env ? IO.popen([@env, @command]) : IO.popen(@command)
|
27
|
+
UI.info("Started process #{@name}")
|
28
|
+
@pid = @process.pid
|
29
|
+
end
|
30
|
+
|
31
|
+
def stop
|
32
|
+
if @process
|
33
|
+
UI.info("Stopping process #{@name}")
|
34
|
+
::Process.kill(@stop_signal, @process.pid)
|
35
|
+
::Process.waitpid(@pid) rescue Errno::ESRCH
|
36
|
+
@process.close
|
37
|
+
@pid = nil
|
38
|
+
UI.info("Stopped process #{@name}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def reload
|
43
|
+
stop
|
44
|
+
start
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_all
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_on_change(paths)
|
52
|
+
reload
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
# This is an example with all options that you can specify for guard-process
|
2
|
+
guard 'process', :name => 'name of your process', :command => 'ruby path/to/your/file.rb', :env => {"ENV1" => "value 1", "ENV2" => "value 2"}, :stop_signal => "KILL" do
|
3
|
+
watch('Gemfile.lock')
|
4
|
+
end
|
5
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class GuardProcessTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ENV['GUARD_ENV'] = 'test'
|
6
|
+
@command = "#{File.expand_path(File.dirname(__FILE__) + '/../run_me.rb')}"
|
7
|
+
@name = "RunMe"
|
8
|
+
@options = {:command => @command, :name => @name}
|
9
|
+
@guard = Guard::Process.new([], @options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@guard.stop if @guard.process_running?
|
14
|
+
ENV['GUARD_ENV'] = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_run_all_returns_true
|
18
|
+
assert @guard.run_all
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_run_on_change_does_a_reload
|
22
|
+
@guard.expects(:reload)
|
23
|
+
@guard.run_on_change("")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_env_is_passed_to_io_popen_if_given
|
27
|
+
@options[:env] = {'VAR1' => 'VALUE 1', 'VAR2' => 'VALUE 2'}
|
28
|
+
IO.expects(:popen).with([@options[:env], @command]).returns(stub_everything)
|
29
|
+
@guard = Guard::Process.new([], @options)
|
30
|
+
@guard.start
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_start_runs_command_and_stop_stops_it
|
34
|
+
Guard::UI.expects(:info).with("Starting process #{@name}")
|
35
|
+
Guard::UI.expects(:info).with("Started process #{@name}")
|
36
|
+
@guard.start
|
37
|
+
assert @guard.process_running?
|
38
|
+
Guard::UI.expects(:info).with("Stopping process #{@name}")
|
39
|
+
Guard::UI.expects(:info).with("Stopped process #{@name}")
|
40
|
+
@guard.stop
|
41
|
+
refute @guard.process_running?
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_reload_stops_and_starts_command
|
45
|
+
@guard.start
|
46
|
+
assert @guard.process_running?
|
47
|
+
@guard.reload
|
48
|
+
assert @guard.process_running?
|
49
|
+
end
|
50
|
+
end
|
data/test/run_me.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-process
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Kremer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-05 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: guard
|
17
|
+
requirement: &24104480 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.4.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *24104480
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: minitest
|
28
|
+
requirement: &24103960 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *24103960
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
requirement: &24103380 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *24103380
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: guard-minitest
|
50
|
+
requirement: &24102840 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *24102840
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: guard-bundler
|
61
|
+
requirement: &24101840 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *24101840
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: &24097500 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *24097500
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rb-inotify
|
83
|
+
requirement: &24096660 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *24096660
|
92
|
+
description: Guard extension to run cli processes
|
93
|
+
email:
|
94
|
+
- mark@socialreferral.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- .gitignore
|
100
|
+
- Gemfile
|
101
|
+
- Guardfile
|
102
|
+
- LICENSE
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- guard-process.gemspec
|
106
|
+
- lib/guard/process.rb
|
107
|
+
- lib/guard/process/templates/Guardfile
|
108
|
+
- test/guard/process_test.rb
|
109
|
+
- test/run_me.rb
|
110
|
+
- test/test_helper.rb
|
111
|
+
has_rdoc: true
|
112
|
+
homepage: ''
|
113
|
+
licenses: []
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ~>
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 1.9.2
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: -2213643143478501703
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.6.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Guard extension to run cli processes
|
139
|
+
test_files: []
|