guard-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +5 -0
- data/README.md +17 -0
- data/Rakefile +2 -0
- data/guard-rails.gemspec +23 -0
- data/lib/guard-rails.rb +1 -0
- data/lib/guard/rails.rb +77 -0
- data/lib/guard/rails/templates/Guardfile +5 -0
- data/lib/guard/rails/version.rb +4 -0
- metadata +81 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Want to restart your Rails development server whilst you work? Now you can!
|
2
|
+
|
3
|
+
guard 'rails', :port => 5000 do
|
4
|
+
watch('Gemfile.lock')
|
5
|
+
watch(%r{^(config|lib)/.*})
|
6
|
+
end
|
7
|
+
|
8
|
+
Four fun options!
|
9
|
+
|
10
|
+
* `:port` is the port number to run on (default `3000`)
|
11
|
+
* `:environment` is the environment to use (default `development`)
|
12
|
+
* `:start_on_start` will start the server when starting Guard (default `true`)
|
13
|
+
* `:force_run` kills any process that's holding open the listen port before attempting to (re)start Rails (default `false`).
|
14
|
+
|
15
|
+
This is super-alpha, but it works for me! Only really hand-tested in Mac OS X. Feel free to fork'n'fix for other
|
16
|
+
OSes, and to add some real tests.
|
17
|
+
|
data/Rakefile
ADDED
data/guard-rails.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "guard/rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "guard-rails"
|
7
|
+
s.version = GuardRails::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["John Bintz"]
|
10
|
+
s.email = ["john@coswellproductions.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Restart Rails when things change in your app}
|
13
|
+
s.description = %q{Restart Rails when things change in your app}
|
14
|
+
|
15
|
+
s.rubyforge_project = "guard-rails"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'guard', '>= 0.2.2'
|
23
|
+
end
|
data/lib/guard-rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'guard/rails'
|
data/lib/guard/rails.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'rbconfig'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Rails < ::Guard::Guard
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
def initialize(watchers = [], options = {})
|
10
|
+
super
|
11
|
+
@options = {
|
12
|
+
:port => 3000,
|
13
|
+
:environment => 'development',
|
14
|
+
:start_on_start => true,
|
15
|
+
:force_run => false
|
16
|
+
}.merge(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
UI.info "Guard::Rails restarting app on port #{options[:port]} using #{options[:environment]} environment."
|
21
|
+
run_all if options[:start_on_start]
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_all
|
25
|
+
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
|
26
|
+
stop_rails ; start_rails
|
27
|
+
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop
|
31
|
+
Notifier.notify("Until next time...", :title => "Rails shutting down.", :image => :pending)
|
32
|
+
stop_rails
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_on_change(paths)
|
36
|
+
run_all
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def pid_file
|
41
|
+
File.expand_path("tmp/pids/#{options[:environment]}.pid")
|
42
|
+
end
|
43
|
+
|
44
|
+
def start_rails
|
45
|
+
kill_unmanaged_pid! if options[:force_run]
|
46
|
+
system %{sh -c 'cd #{Dir.pwd} && rails s -e #{options[:environment]} -p #{options[:port]} --pid #{pid_file} &'}
|
47
|
+
while !File.file?(pid_file)
|
48
|
+
sleep 0.5
|
49
|
+
end
|
50
|
+
UI.info "Rails restarted, pid #{File.read(pid_file)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def stop_rails
|
54
|
+
if File.file?(pid_file)
|
55
|
+
system %{kill -INT #{File.read(pid_file).strip}}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def unmanaged_pid
|
60
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
61
|
+
%x{lsof -P}.each_line { |line|
|
62
|
+
if line["*:#{options[:port]} "]
|
63
|
+
return line.split("\s")[1]
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def kill_unmanaged_pid!
|
71
|
+
if pid = unmanaged_pid
|
72
|
+
system %{kill -INT #{pid}}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Bintz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-31 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: guard
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.2
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Restart Rails when things change in your app
|
28
|
+
email:
|
29
|
+
- john@coswellproductions.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- guard-rails.gemspec
|
42
|
+
- lib/guard-rails.rb
|
43
|
+
- lib/guard/rails.rb
|
44
|
+
- lib/guard/rails/templates/Guardfile
|
45
|
+
- lib/guard/rails/version.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: ""
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 104230829909269231
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 104230829909269231
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: guard-rails
|
76
|
+
rubygems_version: 1.6.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Restart Rails when things change in your app
|
80
|
+
test_files: []
|
81
|
+
|