guard 0.1.0.beta.1 → 0.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/README.rdoc CHANGED
@@ -1,3 +1,155 @@
1
1
  = Guard
2
2
 
3
- Documentation is coming.
3
+ Guard is a command line tool to easly handle events on files modifications.
4
+
5
+ == Features
6
+
7
+ - FSEvent support on Mac OS X (without RubyCocoa!)
8
+ - Inotify support on Linux (beta)
9
+ - Super fast change detection
10
+ - Automatic files modifications detection (even new files are detected)
11
+ - Growl notification (please install {growlnotify}[http://growl.info/documentation/growlnotify.php])
12
+ - Libnotify notification
13
+
14
+ == Install
15
+
16
+ Only Mac OS X (10.5+) & Linux are supported. Tested on Ruby 1.8.7 & 1.9.2dev.
17
+
18
+ Install the gem:
19
+
20
+ gem install guard
21
+
22
+ Add it to your Gemfile (inside test group):
23
+
24
+ gem 'guard'
25
+
26
+ Generate an empty Guardfile with:
27
+
28
+ guard init
29
+
30
+ Add guard(s) you need (see available guards below)
31
+
32
+ == Usage
33
+
34
+ Just launch Guard inside your ruby/rails project with:
35
+
36
+ guard
37
+
38
+ Options list is available with:
39
+
40
+ guard help
41
+
42
+ Signal handlers are used to interact with Guard:
43
+
44
+ - Ctrl-C - Quit Guard (call stop guard(s) method before)
45
+ - Ctrl-\ - Call run_all guard(s) method
46
+ - Ctrl-Z - Call reload guard(s) method
47
+
48
+ == Available Guards
49
+
50
+ - {guard-rspec}[http://github.com/guard/guard-rspec]
51
+
52
+ guard ideas:
53
+
54
+ - guard-spork
55
+ - guard-livereload
56
+ - guard-cucumber
57
+ - guard-test
58
+ - guard-sass
59
+ - guard-bundler
60
+ - others ideas?
61
+
62
+ === Add a guard to your Guardfile
63
+
64
+ Add it to your Gemfile (inside test group):
65
+
66
+ gem '<guard-name>'
67
+
68
+ Add guard definition to your Guardfile with:
69
+
70
+ guard init <guard-name>
71
+
72
+ You are good to go!
73
+
74
+ == Create a guard
75
+
76
+ Create a new guard is very easy, just create a new gem with this basic structure:
77
+
78
+ - lib/
79
+ - guard/
80
+ - guard-name/
81
+ - templates/
82
+ - Guardfile (needed for guard init <guard-name>)
83
+ - guard-name.rb
84
+
85
+ lib/guard/guard-name.rb inherit from guard/guard and should overwrite at least one of the five guard methods. Example:
86
+
87
+ require 'guard'
88
+ require 'guard/guard'
89
+
90
+ module Guard
91
+ class GuardName < Guard
92
+
93
+ # ================
94
+ # = Guard method =
95
+ # ================
96
+
97
+ # Call once when guard starts
98
+ def start
99
+ true
100
+ end
101
+
102
+ # Call with Ctrl-C signal (when Guard quit)
103
+ def stop
104
+ true
105
+ end
106
+
107
+ # Call with Ctrl-Z signal
108
+ def reload
109
+ true
110
+ end
111
+
112
+ # Call with Ctrl-/ signal
113
+ def run_all
114
+ true
115
+ end
116
+
117
+ # Call on file(s) modifications
118
+ def run_on_change(paths)
119
+ true
120
+ end
121
+
122
+ end
123
+ end
124
+
125
+ Looks at available guards code for more concrete example.
126
+
127
+ == Guardfile DSL
128
+
129
+ Guardfile DSL consists of just 2 simple methods: guard & watch. Example:
130
+
131
+ guard 'rspec', :version => 2 do
132
+ watch('^spec/(.*)_spec.rb')
133
+ watch('^lib/(.*)\.rb') { |m| "spec/lib/#{m[1]}_spec.rb" }
134
+ watch('^spec/spec_helper.rb') { "spec" }
135
+ watch('^spec/spec_helper.rb') { `say hello` }
136
+ end
137
+
138
+ - "guard" method allow to add a guard with an optional options hash
139
+ - "watch" method allow to define which files are supervised per this guard. A optional block can be added to overwrite path sending to run_on_change guard method or launch simple command.
140
+
141
+ == TODO
142
+
143
+ - Add more specs, help are welcome because I'm not sure about how to test stuff like this :-)
144
+
145
+ == Development
146
+
147
+ - Source hosted at {GitHub}[http://github.com/guard/guard]
148
+ - Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard/issues]
149
+
150
+ Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
151
+ you make.
152
+
153
+ == Authors
154
+
155
+ {Thibaud Guillaume-Gentil}[http://github.com/thibaudgg].
data/lib/guard/cli.rb CHANGED
@@ -8,13 +8,30 @@ module Guard
8
8
  desc "start", "Starts guard"
9
9
  method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell after each change"
10
10
  def start
11
- Guard.start(options)
11
+ ::Guard.start(options)
12
12
  end
13
13
 
14
14
  desc "version", "Prints the guard's version information"
15
15
  def version
16
- Guard::UI.info "Guard version #{Guard::VERSION}"
16
+ ::Guard::UI.info "Guard version #{Guard::VERSION}"
17
17
  end
18
18
  map %w(-v --version) => :version
19
+
20
+ desc "init [GUARD]", "Generates a Guardfile into the current working directory, or add it given guard"
21
+ def init(guard_name = nil)
22
+ if !File.exist?("Guardfile")
23
+ puts "Writing new Guardfile to #{Dir.pwd}/Guardfile"
24
+ FileUtils.cp(File.expand_path('../templates/Guardfile', __FILE__), 'Guardfile')
25
+ elsif guard_name.nil?
26
+ ::Guard::UI.error "Guardfile already exists at #{Dir.pwd}/Guardfile"
27
+ exit 1
28
+ end
29
+
30
+ if guard_name
31
+ guard_class = ::Guard.get_guard_class(guard_name)
32
+ guard_class.init(guard_name)
33
+ end
34
+ end
35
+
19
36
  end
20
37
  end
data/lib/guard/dsl.rb CHANGED
@@ -10,14 +10,18 @@ module Guard
10
10
  exit 1
11
11
  end
12
12
 
13
+ def self.guardfile_included?(guard_name)
14
+ File.read('Guardfile').include?("guard '#{guard_name}'")
15
+ end
16
+
13
17
  def guard(name, options = {}, &definition)
14
18
  @watchers = []
15
- definition.call
16
- Guard.add_guard(name, @watchers, options)
19
+ definition.call if definition
20
+ ::Guard.add_guard(name, @watchers, options)
17
21
  end
18
22
 
19
23
  def watch(pattern, &action)
20
- @watchers << Guard::Watcher.new(pattern, action)
24
+ @watchers << ::Guard::Watcher.new(pattern, action)
21
25
  end
22
26
 
23
27
  end
data/lib/guard/guard.rb CHANGED
@@ -6,6 +6,22 @@ module Guard
6
6
  @watchers, @options = watchers, options
7
7
  end
8
8
 
9
+ # Guardfile template needed inside guard gem
10
+ def self.init(name)
11
+ if ::Guard::Dsl.guardfile_included?(name)
12
+ ::Guard::UI.info "Guardfile already include #{name} guard"
13
+ else
14
+ content = File.read('Guardfile')
15
+ guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
16
+ File.open('Guardfile', 'wb') do |f|
17
+ f.puts content
18
+ f.puts ""
19
+ f.puts guard
20
+ end
21
+ ::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
22
+ end
23
+ end
24
+
9
25
  # ================
10
26
  # = Guard method =
11
27
  # ================
@@ -50,6 +50,8 @@ module Guard
50
50
 
51
51
  def recent_file?(file)
52
52
  File.mtime(file) >= last_event
53
+ rescue
54
+ false
53
55
  end
54
56
 
55
57
  def update_last_event
@@ -0,0 +1,2 @@
1
+ # A sample Guardfile
2
+ # More info at http://github.com/guard/guard#readme
data/lib/guard/ui.rb CHANGED
@@ -5,7 +5,7 @@ module Guard
5
5
  def info(message, options = {})
6
6
  unless ENV["GUARD_ENV"] == "test"
7
7
  reset_line if options[:reset]
8
- clear if options.key?(:clear) ? options[:clear] : ::Guard.options[:clear]
8
+ clear if options.key?(:clear) ? options[:clear] : (::Guard.options && ::Guard.options[:clear])
9
9
  puts reset_color(message) if message != ''
10
10
  end
11
11
  end
data/lib/guard/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Guard
2
- VERSION = "0.1.0.beta.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/guard/watcher.rb CHANGED
@@ -12,11 +12,10 @@ module Guard
12
12
  if matches = file.match(watcher.pattern)
13
13
  if watcher.action
14
14
  begin
15
- case watcher.action.arity
16
- when -1
17
- result = watcher.action.call
18
- when 1
15
+ if watcher.action.arity == 1
19
16
  result = watcher.action.call(matches)
17
+ else
18
+ result = watcher.action.call
20
19
  end
21
20
  rescue
22
21
  UI.info "Problem with watch action"
data/lib/guard.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'bundler'
2
+
1
3
  module Guard
2
4
 
3
5
  autoload :UI, 'guard/ui'
@@ -16,26 +18,42 @@ module Guard
16
18
  @guards = []
17
19
 
18
20
  Dsl.evaluate_guardfile
19
- Interactor.init_signal_traps
20
-
21
- listener.on_change do |files|
22
- run do
23
- guards.each do |guard|
24
- paths = Watcher.match_files(guard, files)
25
- guard.run_on_change(paths) unless paths.empty?
21
+ if guards.empty?
22
+ UI.error "No guards found in Guardfile, please add it at least one."
23
+ else
24
+ Interactor.init_signal_traps
25
+
26
+ listener.on_change do |files|
27
+ run do
28
+ guards.each do |guard|
29
+ paths = Watcher.match_files(guard, files)
30
+ guard.run_on_change(paths) unless paths.empty?
31
+ end
26
32
  end
27
33
  end
34
+
35
+ UI.info "Guard is now watching at '#{Dir.pwd}'"
36
+ guards.each(&:start)
37
+ listener.start
28
38
  end
29
-
30
- UI.info "Guard is now watching at '#{Dir.pwd}'"
31
- guards.each(&:start)
32
- listener.start
33
39
  end
34
40
 
35
41
  def add_guard(name, watchers = [], options = {})
42
+ guard_class = get_guard_class(name)
43
+ @guards << guard_class.new(watchers, options)
44
+ end
45
+
46
+ def get_guard_class(name)
36
47
  require "guard/#{name.downcase}"
37
48
  guard_class = ObjectSpace.each_object(Class).detect { |c| c.to_s.downcase.match "^guard::#{name.downcase}" }
38
- @guards << guard_class.new(watchers, options)
49
+ rescue LoadError
50
+ UI.error "#{name} guard gem not found, try to add it to your Gemfile."
51
+ end
52
+
53
+ def locate_guard(name)
54
+ spec = Bundler.load.specs.find{|s| s.name == "guard-#{name}" }
55
+ UI.error "Could not find gem '#{name}' in the current Gemfile." unless spec
56
+ spec.full_gem_path
39
57
  end
40
58
 
41
59
  def run
@@ -45,5 +63,4 @@ module Guard
45
63
  end
46
64
 
47
65
  end
48
-
49
66
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196401
5
- prerelease: true
4
+ hash: 27
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
9
  - 0
10
- - beta
11
- - 1
12
- version: 0.1.0.beta.1
10
+ version: 0.1.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Thibaud Guillaume-Gentil
@@ -17,63 +15,78 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-10-03 00:00:00 +02:00
18
+ date: 2010-10-08 00:00:00 +02:00
21
19
  default_executable:
22
20
  dependencies:
23
21
  - !ruby/object:Gem::Dependency
24
- name: bundler
22
+ name: rspec
25
23
  prerelease: false
26
24
  requirement: &id001 !ruby/object:Gem::Requirement
27
25
  none: false
28
26
  requirements:
29
27
  - - ~>
30
28
  - !ruby/object:Gem::Version
31
- hash: 21
29
+ hash: 7712058
32
30
  segments:
33
- - 1
31
+ - 2
34
32
  - 0
35
- - 1
36
- version: 1.0.1
33
+ - 0
34
+ - rc
35
+ version: 2.0.0.rc
37
36
  type: :development
38
37
  version_requirements: *id001
39
38
  - !ruby/object:Gem::Dependency
40
- name: rspec
39
+ name: guard-rspec
41
40
  prerelease: false
42
41
  requirement: &id002 !ruby/object:Gem::Requirement
43
42
  none: false
44
43
  requirements:
45
44
  - - ~>
46
45
  - !ruby/object:Gem::Version
47
- hash: 62196431
46
+ hash: 27
48
47
  segments:
49
- - 2
50
48
  - 0
49
+ - 1
51
50
  - 0
52
- - beta
53
- - 22
54
- version: 2.0.0.beta.22
51
+ version: 0.1.0
55
52
  type: :development
56
53
  version_requirements: *id002
57
54
  - !ruby/object:Gem::Dependency
58
- name: thor
55
+ name: bundler
59
56
  prerelease: false
60
57
  requirement: &id003 !ruby/object:Gem::Requirement
61
58
  none: false
62
59
  requirements:
63
60
  - - ~>
64
61
  - !ruby/object:Gem::Version
65
- hash: 35
62
+ hash: 19
66
63
  segments:
64
+ - 1
67
65
  - 0
68
- - 14
69
66
  - 2
70
- version: 0.14.2
67
+ version: 1.0.2
71
68
  type: :runtime
72
69
  version_requirements: *id003
73
70
  - !ruby/object:Gem::Dependency
74
- name: sys-uname
71
+ name: thor
75
72
  prerelease: false
76
73
  requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 33
79
+ segments:
80
+ - 0
81
+ - 14
82
+ - 3
83
+ version: 0.14.3
84
+ type: :runtime
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: sys-uname
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
77
90
  none: false
78
91
  requirements:
79
92
  - - ~>
@@ -85,11 +98,11 @@ dependencies:
85
98
  - 4
86
99
  version: 0.8.4
87
100
  type: :runtime
88
- version_requirements: *id004
101
+ version_requirements: *id005
89
102
  - !ruby/object:Gem::Dependency
90
103
  name: growl
91
104
  prerelease: false
92
- requirement: &id005 !ruby/object:Gem::Requirement
105
+ requirement: &id006 !ruby/object:Gem::Requirement
93
106
  none: false
94
107
  requirements:
95
108
  - - ~>
@@ -101,25 +114,27 @@ dependencies:
101
114
  - 3
102
115
  version: 1.0.3
103
116
  type: :runtime
104
- version_requirements: *id005
117
+ version_requirements: *id006
105
118
  - !ruby/object:Gem::Dependency
106
119
  name: rb-inotify
107
120
  prerelease: false
108
- requirement: &id006 !ruby/object:Gem::Requirement
121
+ requirement: &id007 !ruby/object:Gem::Requirement
109
122
  none: false
110
123
  requirements:
111
- - - ">="
124
+ - - ~>
112
125
  - !ruby/object:Gem::Version
113
- hash: 3
126
+ hash: 61
114
127
  segments:
115
128
  - 0
116
- version: "0"
129
+ - 8
130
+ - 1
131
+ version: 0.8.1
117
132
  type: :runtime
118
- version_requirements: *id006
133
+ version_requirements: *id007
119
134
  - !ruby/object:Gem::Dependency
120
135
  name: libnotify
121
136
  prerelease: false
122
- requirement: &id007 !ruby/object:Gem::Requirement
137
+ requirement: &id008 !ruby/object:Gem::Requirement
123
138
  none: false
124
139
  requirements:
125
140
  - - ~>
@@ -131,8 +146,8 @@ dependencies:
131
146
  - 3
132
147
  version: 0.1.3
133
148
  type: :runtime
134
- version_requirements: *id007
135
- description: Guard is a command line tool to easly manage script launch when your files change
149
+ version_requirements: *id008
150
+ description: Guard is a command line tool to easly handle events on files modifications.
136
151
  email:
137
152
  - thibaud@thibaud.me
138
153
  executables:
@@ -153,6 +168,7 @@ files:
153
168
  - lib/guard/interactor.rb
154
169
  - lib/guard/listener.rb
155
170
  - lib/guard/notifier.rb
171
+ - lib/guard/templates/Guardfile
156
172
  - lib/guard/ui.rb
157
173
  - lib/guard/version.rb
158
174
  - lib/guard/watcher.rb
@@ -182,20 +198,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
198
  required_rubygems_version: !ruby/object:Gem::Requirement
183
199
  none: false
184
200
  requirements:
185
- - - ">"
201
+ - - ">="
186
202
  - !ruby/object:Gem::Version
187
- hash: 25
203
+ hash: 23
188
204
  segments:
189
205
  - 1
190
206
  - 3
191
- - 1
192
- version: 1.3.1
207
+ - 6
208
+ version: 1.3.6
193
209
  requirements: []
194
210
 
195
211
  rubyforge_project: guard
196
212
  rubygems_version: 1.3.7
197
213
  signing_key:
198
214
  specification_version: 3
199
- summary: Guard keep an eye on your files event
215
+ summary: Guard keep an eye on your files modifications.
200
216
  test_files: []
201
217