when-files-change 0.2

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.markdown ADDED
@@ -0,0 +1,30 @@
1
+ When Files Change
2
+ =================
3
+
4
+ Do something when files change, it's that simple.
5
+
6
+ When files change, run my tests:
7
+
8
+ when-files-change -- rake test
9
+
10
+ When files change, build my css assets:
11
+
12
+ when-files-change -- make
13
+
14
+ When files change, make me a sandwich:
15
+
16
+ when-files-change -- sudo make-me-a-sandwhich
17
+
18
+ By default `when-files-change` ignores log folders, hidden files in your root, and source control directories. You can explicitly list any other files you want to ignore:
19
+
20
+ when-files-change --ignore 'build' -- make
21
+
22
+ To quit press CTRL-D or CTRL-C. To force the command to be run, press Enter.
23
+
24
+ That's about all there is to it. Most of the credit for this tool goes to the [guard/listen](https://github.com/guard/listen) library since it does all leg work. `when-files-change` just wraps it in an easy to use command.
25
+
26
+ Used with a build tool like Rake, Make, or some other *ake, you can save yourself a lot of time and hassle. If this doesn't suit your needs, take a look at [Guard](https://github.com/guard/guard) or [Watchr](https://github.com/bevry/watchr), both projects allow special rules for processing various types of events.
27
+
28
+ -----
29
+
30
+ Adam Sanderson, http://www.monkeyandcrow.com
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require File.dirname(__FILE__) + '/../lib/change_listener'
4
+
5
+ # Options
6
+ ignored_paths = nil
7
+
8
+ opts = OptionParser.new do |opts|
9
+ opts.banner = "Usage: #{File.basename($0)} [options] -- command [arguments]"
10
+ opts.separator ""
11
+
12
+ opts.on("-i", "--ignore PATHS", Array, "Ignore changes made at these paths") do |paths|
13
+ ignore_paths = paths
14
+ end
15
+ opts.parse! ARGV
16
+ end
17
+
18
+ command = ARGV.shift
19
+ unless command
20
+ puts opts
21
+ exit 1
22
+ end
23
+
24
+ listener = ChangeListener.new(command, *ARGV)
25
+ listener.ignore_paths(ignored_paths) if ignored_paths
26
+ listener.start
27
+
28
+ # Catch signals so we can exit gracefully
29
+ trap('SIGINT' ){ puts; exit 1 }
30
+ trap('SIGQUIT'){ puts; exit 1 }
31
+
32
+ # Wait for a ctrl-d to quit
33
+ while char = STDIN.getc
34
+ listener.execute if char == "\n"
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'listen'
2
+ require 'file_glob'
3
+
4
+ class ChangeListener
5
+ attr_reader :listener
6
+ attr_reader :command
7
+ attr_reader :arguments
8
+
9
+ def initialize(command, *arguments)
10
+ @command = command
11
+ @arguments = arguments
12
+ @listener = Listen.to('./').ignore(/^\.\w+/)
13
+
14
+ @listener.change{ execute }
15
+ end
16
+
17
+ def start
18
+ listener.start(false)
19
+ end
20
+
21
+ def execute
22
+ listener.pause
23
+ Kernel.system(command, *arguments)
24
+ listener.unpause
25
+ end
26
+
27
+ def ignore(*regexps)
28
+ @listener.ignore(*regexps)
29
+ end
30
+
31
+ def ignore_path(*paths)
32
+ globs = paths.map{|p| FileGlob.new(p)}
33
+
34
+ @listener.ignore(*globs)
35
+ end
36
+ end
data/lib/file_glob.rb ADDED
@@ -0,0 +1,19 @@
1
+ class FileGlob
2
+ attr_reader :pattern
3
+
4
+ def initialize(pattern)
5
+ @pattern = pattern
6
+ end
7
+
8
+ def =~ path
9
+ File.fnmatch?(pattern, path)
10
+ end
11
+
12
+ def to_s
13
+ pattern
14
+ end
15
+
16
+ def inspect
17
+ "<#FileGlob #{pattern}>"
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: when-files-change
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ version: "0.2"
9
+ platform: ruby
10
+ authors:
11
+ - Adam Sanderson
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2013-02-26 00:00:00 -08:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: listen
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 7
30
+ version: "0.7"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Whenever files in your working directory change, execute a command, such as "rake test".
34
+ email:
35
+ - netghost@gmail.com
36
+ executables:
37
+ - when-files-change
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - bin/when-files-change
44
+ - lib/change_listener.rb
45
+ - lib/file_glob.rb
46
+ - README.markdown
47
+ has_rdoc: true
48
+ homepage: https://github.com/adamsanderson/when-files-change
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
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
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: When files change, do something.
79
+ test_files: []
80
+