rego 1.4.0 → 1.5.1

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.
Files changed (7) hide show
  1. data/bin/rego +64 -21
  2. data/d/a.rb +1 -0
  3. data/d/rego +282 -0
  4. data/lib/rego.rb +20 -3
  5. data/rego.gemspec +5 -6
  6. metadata +4 -3
  7. data/~/foo +0 -0
data/bin/rego CHANGED
@@ -47,26 +47,20 @@ Main {
47
47
  end
48
48
 
49
49
  def parse_the_command_line
50
- pos = argv.index('--')
50
+ argv = ARGV.map{|arg| "#{ arg }"}
51
51
 
52
- =begin
53
- if pos
54
- @command = argv[0...pos].join(' ')
55
- @paths = argv[pos + 1 .. -1]
56
- else
57
- @command = argv[0..-1].join(' ')
58
- @paths = []
52
+ @paths, @command = argv.join(' ').split('--', 2)
53
+
54
+ @paths = @paths.to_s.strip.scan(/[^\s]+/)
55
+ @command = @command.to_s.strip
56
+
57
+ if @paths.empty?
58
+ @paths.push('.')
59
59
  end
60
- =end
61
- if pos
62
- @paths = argv[0 ... pos]
63
- @command = argv[pos + 1 .. -1].join(' ')
64
- else
65
- @paths = []
66
- @command = argv[0..-1].join(' ')
60
+
61
+ if @command.empty?
62
+ @command = 'echo @'
67
63
  end
68
- @command = 'echo @' if @paths.empty?
69
- @paths = %w[ app lib test config a.rb Rakefile ] if @paths.empty?
70
64
 
71
65
  @paths.map!{|path| test(?d, path) ? [path, Dir.glob(File.join(path, '**/**'))] : path}
72
66
  @paths.flatten!
@@ -74,7 +68,7 @@ Main {
74
68
  @paths.uniq!
75
69
  @paths.map! do |path|
76
70
  begin
77
- Pathname.new(path).realpath.to_s
71
+ Rego.realpath(path)
78
72
  rescue Object
79
73
  nil
80
74
  end
@@ -95,9 +89,9 @@ Main {
95
89
 
96
90
  @paths.each do |path|
97
91
  if test(?d, path)
98
- @directories.push(path)
92
+ @directories.push(Rego.realpath(path))
99
93
  else
100
- @files.push(path)
94
+ @files.push(Rego.realpath(path))
101
95
  @directories.push(Rego.realpath(File.dirname(path)))
102
96
  end
103
97
  end
@@ -143,10 +137,56 @@ Main {
143
137
  #
144
138
  fsevent = FSEvent.new
145
139
 
140
+ options = {
141
+ :latency => 0.42,
142
+ :no_defer => true,
143
+ :file_events => true,
144
+ :since_when => 0
145
+ }
146
+
147
+ fsevent.watch(@directories, options) do |*args|
148
+ unless $running
149
+ $running = true
150
+
151
+ args.flatten.each do |dir|
152
+ glob = File.join(dir, '**/**')
153
+ entries = Dir.glob(glob)
154
+
155
+ entries.each do |entry|
156
+ entry = File.expand_path(entry)
157
+ next unless stats.has_key?(entry)
158
+
159
+ begin
160
+ stats[entry] ||= File.stat(entry)
161
+ before = stats[entry]
162
+ after = File.stat(entry)
163
+ rescue
164
+ next
165
+ end
166
+
167
+ unless before.mtime == after.mtime
168
+ stats[entry] = after
169
+ rego[ entry ]
170
+ end
171
+ end
172
+ end
173
+ end
174
+ $running = false
175
+ end
176
+
177
+ begin
178
+ fsevent.run
179
+ rescue SignalException
180
+ exit(0)
181
+ end
182
+ end
183
+ =begin
184
+ fsevent = FSEvent.new
185
+
146
186
  fsevent.watch(
147
187
 
148
188
  @directories,
149
- :latency => 0.00042,
189
+ :latency => 0.42,
150
190
  :no_defer => true,
151
191
  :file_events => true,
152
192
  :watch_root => true,
@@ -188,6 +228,7 @@ Main {
188
228
  exit(0)
189
229
  end
190
230
  end
231
+ =end
191
232
  }
192
233
 
193
234
 
@@ -195,6 +236,7 @@ BEGIN {
195
236
  # setup a child process to catch signals and brutally shut down the parent as
196
237
  # a monkey-patch to listen/rb-fsevent's busted ctrl-c handling...
197
238
  #
239
+ if false
198
240
  unless((pid = fork))
199
241
  ppid = Process.ppid
200
242
 
@@ -222,6 +264,7 @@ BEGIN {
222
264
  exit!(0)
223
265
  end
224
266
  end
267
+ end
225
268
 
226
269
  require 'pathname'
227
270
 
data/d/a.rb ADDED
@@ -0,0 +1 @@
1
+ 42
data/d/rego ADDED
@@ -0,0 +1,282 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ Main {
4
+
5
+ name <<-__
6
+
7
+ rego
8
+
9
+ __
10
+
11
+ description <<-__
12
+
13
+ run arbitrary commands easily when files change
14
+
15
+ __
16
+
17
+ examples <<-__
18
+
19
+ ### gem install rego
20
+
21
+
22
+ # say hai whenever the file foo.txt changes
23
+ #
24
+ ~> rego foo.txt -- echo hai
25
+
26
+ # say hai whenever any file (recursively) in bar changes
27
+ #
28
+ ~> rego ./bar/ -- echo hai
29
+
30
+ # echo *the file that changed* when any file (recursively) in bar changes
31
+ #
32
+ ~> rego ./bar/ -- echo "@ was changed"
33
+
34
+ # run a specific test whenever anything in lib, test, app, or config changes
35
+ #
36
+ ~> rego {lib,test,app,config} -- ruby -Itest ./test/units/foo_test.rb --name teh_test
37
+
38
+ # run a specific test whenever it, or your app, has changed
39
+ #
40
+ ~> rego ./test -- ruby -Itest @
41
+ __
42
+
43
+ def run
44
+ parse_the_command_line
45
+ print_a_summary_of_watched_files
46
+ loop_watching_files_and_running_commands
47
+ end
48
+
49
+ def parse_the_command_line
50
+ argv = ARGV.map{|arg| "#{ arg }"}
51
+
52
+ @paths, @command = argv.join(' ').split('--', 2)
53
+
54
+ @paths = @paths.to_s.strip.scan(/[^\s]+/)
55
+ @command = @command.to_s.strip
56
+
57
+ if @paths.empty?
58
+ @paths.push('.')
59
+ end
60
+
61
+ if @command.empty?
62
+ @command = 'echo @'
63
+ end
64
+
65
+ @paths.map!{|path| test(?d, path) ? [path, Dir.glob(File.join(path, '**/**'))] : path}
66
+ @paths.flatten!
67
+ @paths.compact!
68
+ @paths.uniq!
69
+ @paths.map! do |path|
70
+ begin
71
+ Rego.realpath(path)
72
+ rescue Object
73
+ nil
74
+ end
75
+ end
76
+ @paths.compact!
77
+ end
78
+
79
+ def print_a_summary_of_watched_files
80
+ puts "## #{ @command }"
81
+ puts "#"
82
+ puts @paths.join("\n")
83
+ puts
84
+ end
85
+
86
+ def loop_watching_files_and_running_commands
87
+ @directories = []
88
+ @files = []
89
+
90
+ @paths.each do |path|
91
+ if test(?d, path)
92
+ @directories.push(Rego.realpath(path))
93
+ else
94
+ @files.push(Rego.realpath(path))
95
+ @directories.push(Rego.realpath(File.dirname(path)))
96
+ end
97
+ end
98
+
99
+ @directories.uniq!
100
+ @files.uniq!
101
+
102
+ stats = {}
103
+
104
+ @files.each do |file|
105
+ begin
106
+ stats[file] = File.stat(file)
107
+ rescue
108
+ nil
109
+ end
110
+ end
111
+
112
+ #
113
+ n = '0'
114
+ line = '#' * 42
115
+ $running = false
116
+
117
+ #
118
+ rego =
119
+ proc do |*args|
120
+ path = args.shift
121
+ cmd = path ? @command.gsub(/@/, path) : @command
122
+
123
+ puts line
124
+
125
+ Rego.say("# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ cmd }", :color => :magenta)
126
+ puts
127
+
128
+ system(cmd)
129
+ puts
130
+
131
+ Rego.say("# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ $?.exitstatus }", :color => :yellow)
132
+ puts
133
+
134
+ n.succ!
135
+ end
136
+
137
+ #
138
+ fsevent = FSEvent.new
139
+
140
+ options = {
141
+ :latency => 0.42,
142
+ :no_defer => true,
143
+ :file_events => true,
144
+ :since_when => 0
145
+ }
146
+
147
+ fsevent.watch(@directories, options) do |*args|
148
+ unless $running
149
+ $running = true
150
+
151
+ args.flatten.each do |dir|
152
+ glob = File.join(dir, '**/**')
153
+ entries = Dir.glob(glob)
154
+
155
+ entries.each do |entry|
156
+ entry = File.expand_path(entry)
157
+ next unless stats.has_key?(entry)
158
+
159
+ begin
160
+ stats[entry] ||= File.stat(entry)
161
+ before = stats[entry]
162
+ after = File.stat(entry)
163
+ rescue
164
+ next
165
+ end
166
+
167
+ unless before.mtime == after.mtime
168
+ stats[entry] = after
169
+ rego[ entry ]
170
+ end
171
+ end
172
+ end
173
+ end
174
+ $running = false
175
+ end
176
+
177
+ begin
178
+ fsevent.run
179
+ rescue SignalException
180
+ exit(0)
181
+ end
182
+ end
183
+ =begin
184
+ fsevent = FSEvent.new
185
+
186
+ fsevent.watch(
187
+
188
+ @directories,
189
+ :latency => 0.42,
190
+ :no_defer => true,
191
+ :file_events => true,
192
+ :watch_root => true,
193
+ :since_when => 0
194
+
195
+ ) do |*args|
196
+ unless $running
197
+ $running = true
198
+
199
+ args.flatten.each do |dir|
200
+ glob = File.join(dir, '**/**')
201
+ entries = Dir.glob(glob)
202
+
203
+ entries.each do |entry|
204
+ entry = File.expand_path(entry)
205
+ next unless stats.has_key?(entry)
206
+
207
+ begin
208
+ stats[entry] ||= File.stat(entry)
209
+ before = stats[entry]
210
+ after = File.stat(entry)
211
+ rescue
212
+ next
213
+ end
214
+
215
+ unless before.mtime == after.mtime
216
+ stats[entry] = after
217
+ rego[ entry ]
218
+ end
219
+ end
220
+ end
221
+ end
222
+ $running = false
223
+ end
224
+
225
+ begin
226
+ fsevent.run
227
+ rescue SignalException
228
+ exit(0)
229
+ end
230
+ end
231
+ =end
232
+ }
233
+
234
+
235
+ BEGIN {
236
+ # setup a child process to catch signals and brutally shut down the parent as
237
+ # a monkey-patch to listen/rb-fsevent's busted ctrl-c handling...
238
+ #
239
+ if false
240
+ unless((pid = fork))
241
+ ppid = Process.ppid
242
+
243
+ begin
244
+ trap('SIGINT'){
245
+ %w(
246
+ SIGTERM SIGINT SIGQUIT SIGKILL
247
+ ).each do |signal|
248
+
249
+ begin
250
+ Process.kill("-#{ signal }", ppid)
251
+ rescue Object
252
+ nil
253
+ end
254
+
255
+ sleep(rand)
256
+ end
257
+ }
258
+
259
+ loop do
260
+ Process.kill(0, ppid)
261
+ sleep(1)
262
+ end
263
+ rescue Object => e
264
+ exit!(0)
265
+ end
266
+ end
267
+ end
268
+
269
+ require 'pathname'
270
+
271
+ this = Pathname.new(__FILE__).realpath.to_s
272
+ bindir = File.dirname(this)
273
+ rootdir = File.dirname(bindir)
274
+ libdir = File.join(rootdir, 'lib')
275
+ rego = File.join(libdir, 'rego.rb')
276
+
277
+ require(rego)
278
+
279
+ STDOUT.sync = true
280
+ STDERR.sync = true
281
+ STDIN.sync = true
282
+ }
@@ -1,9 +1,10 @@
1
1
  require 'time'
2
2
  require 'pathname'
3
3
  require 'yaml'
4
+ require 'tmpdir'
4
5
 
5
6
  module Rego
6
- Version = '1.4.0' unless defined?(Version)
7
+ Version = '1.5.1' unless defined?(Version)
7
8
 
8
9
  def version
9
10
  Rego::Version
@@ -36,7 +37,24 @@ module Rego
36
37
  end
37
38
 
38
39
  def realpath(path)
39
- Pathname.new(path.to_s).realpath.to_s
40
+ Pathname.new(path).realpath.to_s
41
+ end
42
+
43
+ def tmpdir(&block)
44
+ tmpdir = File.join(Dir.tmpdir, ['rego', Process.ppid.to_s, Process.pid.to_s, Thread.current.object_id.to_s].join('-') + '.d')
45
+
46
+ FileUtils.mkdir_p(tmpdir)
47
+
48
+ if block
49
+ begin
50
+ Dir.chdir(tmpdir, &block)
51
+ ensure
52
+ FileUtils.rm_rf(tmpdir)
53
+ at_exit{ `rm -rf #{ tmpdir }` }
54
+ end
55
+ else
56
+ tmpdir
57
+ end
40
58
  end
41
59
 
42
60
  def say(phrase, *args)
@@ -108,4 +126,3 @@ if defined?(gem)
108
126
  require(lib)
109
127
  end
110
128
  end
111
-
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "rego"
6
- spec.version = "1.4.0"
6
+ spec.version = "1.5.1"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "rego"
9
9
  spec.description = "description: rego kicks the ass"
@@ -11,15 +11,14 @@ Gem::Specification::new do |spec|
11
11
  spec.files =
12
12
  ["README",
13
13
  "Rakefile",
14
- "bar",
15
- "bar/foo",
16
14
  "bin",
17
15
  "bin/rego",
16
+ "d",
17
+ "d/a.rb",
18
+ "d/rego",
18
19
  "lib",
19
20
  "lib/rego.rb",
20
- "rego.gemspec",
21
- "~",
22
- "~/foo"]
21
+ "rego.gemspec"]
23
22
 
24
23
  spec.executables = ["rego"]
25
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rego
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-19 00:00:00.000000000 Z
12
+ date: 2013-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: main
@@ -53,9 +53,10 @@ files:
53
53
  - README
54
54
  - Rakefile
55
55
  - bin/rego
56
+ - d/a.rb
57
+ - d/rego
56
58
  - lib/rego.rb
57
59
  - rego.gemspec
58
- - ~/foo
59
60
  homepage: https://github.com/ahoward/rego
60
61
  licenses: []
61
62
  post_install_message:
data/~/foo DELETED
File without changes