rego 1.0.0 → 1.2.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.
Files changed (5) hide show
  1. data/README +5 -5
  2. data/bin/rego +160 -40
  3. data/lib/rego.rb +3 -2
  4. data/rego.gemspec +10 -3
  5. metadata +20 -9
data/README CHANGED
@@ -23,21 +23,21 @@ EXAMPLES
23
23
 
24
24
  # say hai whenever the file foo.txt changes
25
25
  #
26
- ~> rego echo hai -- foo.txt
26
+ ~> rego foo.txt -- echo hai
27
27
 
28
28
  # say hai whenever any file (recursively) in bar changes
29
29
  #
30
- ~> rego echo hai -- ./bar/
30
+ ~> rego ./bar/ -- echo hai
31
31
 
32
32
  # echo *the file that changed* when any file (recursively) in bar changes
33
33
  #
34
- ~> rego echo "@ was changed" -- ./bar/
34
+ ~> rego ./bar/ -- echo "@ was changed"
35
35
 
36
36
  # run a specific test whenever anything in lib, test, app, or config changes
37
37
  #
38
- ~> rego ruby -Itest ./test/units/foo_test.rb --name teh_test -- {lib,test,app,config}
38
+ ~> rego {lib,test,app,config} -- ruby -Itest ./test/units/foo_test.rb --name teh_test
39
39
 
40
40
  # run a specific test whenever it, or your app, has changed
41
41
  #
42
- ~> rego ruby -Itest @ -- ./test
42
+ ~> rego ./test -- ruby -Itest @
43
43
 
data/bin/rego CHANGED
@@ -18,26 +18,26 @@ Main {
18
18
 
19
19
  ### gem install rego
20
20
 
21
-
21
+
22
22
  # say hai whenever the file foo.txt changes
23
23
  #
24
- ~> rego echo hai -- foo.txt
24
+ ~> rego foo.txt -- echo hai
25
25
 
26
- # say hai whenever any file (recursively) in bar changes
26
+ # say hai whenever any file (recursively) in bar changes
27
27
  #
28
- ~> rego echo hai -- ./bar/
28
+ ~> rego ./bar/ -- echo hai
29
29
 
30
- # echo *the file that changed* when any file (recursively) in bar changes
30
+ # echo *the file that changed* when any file (recursively) in bar changes
31
31
  #
32
- ~> rego echo "@ was changed" -- ./bar/
32
+ ~> rego ./bar/ -- echo "@ was changed"
33
33
 
34
34
  # run a specific test whenever anything in lib, test, app, or config changes
35
35
  #
36
- ~> rego ruby -Itest ./test/units/foo_test.rb --name teh_test -- {lib,test,app,config}
36
+ ~> rego {lib,test,app,config} -- ruby -Itest ./test/units/foo_test.rb --name teh_test
37
37
 
38
38
  # run a specific test whenever it, or your app, has changed
39
39
  #
40
- ~> rego ruby -Itest @ -- ./test
40
+ ~> rego ./test -- ruby -Itest @
41
41
  __
42
42
 
43
43
  def run
@@ -47,34 +47,39 @@ Main {
47
47
  end
48
48
 
49
49
  def parse_the_command_line
50
- pos = ARGV.index('--')
50
+ pos = argv.index('--')
51
51
 
52
52
  =begin
53
53
  if pos
54
- @command = ARGV[0...pos].join(' ')
55
- @paths = ARGV[pos + 1 .. -1]
54
+ @command = argv[0...pos].join(' ')
55
+ @paths = argv[pos + 1 .. -1]
56
56
  else
57
- @command = ARGV[0..-1].join(' ')
57
+ @command = argv[0..-1].join(' ')
58
58
  @paths = []
59
59
  end
60
60
  =end
61
61
  if pos
62
- @paths = ARGV[0 ... pos]
63
- @command = ARGV[pos + 1 .. -1].join(' ')
62
+ @paths = argv[0 ... pos]
63
+ @command = argv[pos + 1 .. -1].join(' ')
64
64
  else
65
65
  @paths = []
66
- @command = ARGV[0..-1].join(' ')
66
+ @command = argv[0..-1].join(' ')
67
67
  end
68
68
  @command = 'echo @' if @paths.empty?
69
- @paths = %w[.] if @paths.empty?
69
+ @paths = %w[ app lib test config a.rb Rakefile ] if @paths.empty?
70
70
 
71
71
  @paths.map!{|path| test(?d, path) ? [path, Dir.glob(File.join(path, '**/**'))] : path}
72
72
  @paths.flatten!
73
73
  @paths.compact!
74
74
  @paths.uniq!
75
75
  @paths.map! do |path|
76
- Pathname.new(path).realpath.to_s
76
+ begin
77
+ Pathname.new(path).realpath.to_s
78
+ rescue Object
79
+ nil
80
+ end
77
81
  end
82
+ @paths.compact!
78
83
  end
79
84
 
80
85
  def print_a_summary_of_watched_files
@@ -85,22 +90,24 @@ Main {
85
90
  end
86
91
 
87
92
  def loop_watching_files_and_running_commands
88
- directories = []
89
- files = []
93
+ @directories = []
94
+ @files = []
95
+
90
96
  @paths.each do |path|
91
97
  if test(?d, path)
92
- directories.push(path)
98
+ @directories.push(path)
93
99
  else
94
- files.push(path)
95
- directories.push(File.dirname(path))
100
+ @files.push(path)
101
+ @directories.push(File.dirname(path))
96
102
  end
97
103
  end
98
- directories.uniq!
99
- files.uniq!
104
+
105
+ @directories.uniq!
106
+ @files.uniq!
100
107
 
101
108
  stats = {}
102
109
 
103
- files.each do |file|
110
+ @files.each do |file|
104
111
  begin
105
112
  stats[file] = File.stat(file)
106
113
  rescue
@@ -108,28 +115,54 @@ Main {
108
115
  end
109
116
  end
110
117
 
111
- fsevent = FSEvent.new
112
-
113
118
  n = '0'
114
119
  line = '#' * 42
115
120
  $running = false
116
121
 
117
- rego = proc do |*args|
118
- entry = args.shift
119
- cmd = entry ? @command.gsub(/@/, entry) : @command
120
- puts line
121
- puts "# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ cmd }"
122
- puts
123
- system(cmd)
124
- puts
125
- puts "# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ $?.exitstatus }"
126
- puts
127
- n.succ!
128
- end
122
+ rego =
123
+ proc do |*args|
124
+ path = args.shift
125
+ cmd = path ? @command.gsub(/@/, path) : @command
126
+
127
+ puts line
128
+
129
+ say("# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ cmd }", :color => :magenta)
130
+ puts
131
+
132
+ system(cmd)
133
+ puts
134
+
135
+ say("# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ $?.exitstatus }", :color => :yellow)
136
+ puts
137
+
138
+ n.succ!
139
+ end
129
140
 
130
141
  rego[ false ]
131
142
 
132
- fsevent.watch(directories) do |*args|
143
+ begin
144
+ Listen.to!(*@directories, :latency => 0.1) do |modified, added, removed|
145
+ [modified, added, removed].flatten.compact.uniq.each do |path|
146
+ rego[path]
147
+ end
148
+ end
149
+ rescue SignalException
150
+ STDERR.reopen('/dev/null', 'w+')
151
+ exit(42)
152
+ end
153
+
154
+
155
+ =begin
156
+ fsevent = FSEvent.new
157
+
158
+ fsevent.watch(
159
+ @directories,
160
+ :latency => 0.00042,
161
+ :no_defer => true,
162
+ :file_events => true,
163
+ :watch_root => true,
164
+ :since_when => 0
165
+ ) do |*args|
133
166
  unless $running
134
167
  $running = true
135
168
 
@@ -160,11 +193,98 @@ Main {
160
193
  end
161
194
 
162
195
  fsevent.run
196
+ =end
163
197
  end
164
198
  }
165
199
 
166
200
 
167
201
  BEGIN {
202
+ # setup a child process to catch signals and brutally shut down the parent as
203
+ # a monkey-patch to listen/rb-fsevent's busted ctrl-c handling...
204
+ #
205
+ unless((pid = fork))
206
+ ppid = Process.ppid
207
+
208
+ begin
209
+ trap('SIGINT'){
210
+ %w(
211
+ SIGTERM SIGINT SIGQUIT SIGKILL
212
+ ).each do |signal|
213
+
214
+ begin
215
+ Process.kill("-#{ signal }", ppid)
216
+ rescue Object
217
+ nil
218
+ end
219
+
220
+ sleep(rand)
221
+ end
222
+ }
223
+
224
+ loop do
225
+ Process.kill(0, ppid)
226
+ sleep(1)
227
+ end
228
+ rescue Object => e
229
+ exit!(0)
230
+ end
231
+ end
232
+
233
+ ANSI = {
234
+ :clear => "\e[0m",
235
+ :reset => "\e[0m",
236
+ :erase_line => "\e[K",
237
+ :erase_char => "\e[P",
238
+ :bold => "\e[1m",
239
+ :dark => "\e[2m",
240
+ :underline => "\e[4m",
241
+ :underscore => "\e[4m",
242
+ :blink => "\e[5m",
243
+ :reverse => "\e[7m",
244
+ :concealed => "\e[8m",
245
+ :black => "\e[30m",
246
+ :red => "\e[31m",
247
+ :green => "\e[32m",
248
+ :yellow => "\e[33m",
249
+ :blue => "\e[34m",
250
+ :magenta => "\e[35m",
251
+ :cyan => "\e[36m",
252
+ :white => "\e[37m",
253
+ :on_black => "\e[40m",
254
+ :on_red => "\e[41m",
255
+ :on_green => "\e[42m",
256
+ :on_yellow => "\e[43m",
257
+ :on_blue => "\e[44m",
258
+ :on_magenta => "\e[45m",
259
+ :on_cyan => "\e[46m",
260
+ :on_white => "\e[47m"
261
+ }
262
+
263
+ module Kernel
264
+ private
265
+ def say(phrase, *args)
266
+ options = args.last.is_a?(Hash) ? args.pop : {}
267
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
268
+ keys = options.keys
269
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
270
+
271
+ color = options[:color]
272
+ bold = options.has_key?(:bold)
273
+
274
+ parts = [phrase]
275
+
276
+ if STDOUT.tty?
277
+ parts.unshift(ANSI[color]) if color
278
+ parts.unshift(ANSI[:bold]) if bold
279
+ parts.push(ANSI[:clear]) if parts.size > 1
280
+ end
281
+
282
+ method = options[:method] || :puts
283
+
284
+ send(method, parts.join)
285
+ end
286
+ end
287
+
168
288
  require 'pathname'
169
289
  this = Pathname.new(__FILE__).realpath.to_s
170
290
  bindir = File.dirname(this)
@@ -3,7 +3,7 @@ require 'pathname'
3
3
  require 'yaml'
4
4
 
5
5
  module Rego
6
- Version = '1.0.0' unless defined?(Version)
6
+ Version = '1.2.0' unless defined?(Version)
7
7
 
8
8
  def version
9
9
  Rego::Version
@@ -12,7 +12,8 @@ module Rego
12
12
  def dependencies
13
13
  {
14
14
  'main' => [ 'main' , ' >= 4.8.1' ] ,
15
- 'rb-fsevent' => [ 'rb-fsevent' , ' >= 0.4.3.1' ]
15
+ #'rb-fsevent' => [ 'rb-fsevent' , ' >= 0.4.3.1' ] ,
16
+ 'listen' => [ 'listen' , ' >= 1.0.2' ] ,
16
17
  }
17
18
  end
18
19
 
@@ -3,13 +3,20 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "rego"
6
- spec.version = "1.0.0"
6
+ spec.version = "1.2.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "rego"
9
9
  spec.description = "description: rego kicks the ass"
10
10
 
11
11
  spec.files =
12
- ["README", "Rakefile", "bin", "bin/rego", "lib", "lib/rego.rb", "rego.gemspec"]
12
+ ["README",
13
+ "Rakefile",
14
+ "bin",
15
+ "bin/rego",
16
+ "lib",
17
+ "lib/rego.rb",
18
+ "rego.gemspec",
19
+ "~"]
13
20
 
14
21
  spec.executables = ["rego"]
15
22
 
@@ -20,7 +27,7 @@ Gem::Specification::new do |spec|
20
27
 
21
28
  spec.add_dependency(*["main", " >= 4.8.1"])
22
29
 
23
- spec.add_dependency(*["rb-fsevent", " >= 0.4.3.1"])
30
+ spec.add_dependency(*["listen", " >= 1.0.2"])
24
31
 
25
32
 
26
33
  spec.extensions.push(*[])
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.0.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-26 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: main
16
- requirement: &70118988773040 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,18 +21,28 @@ dependencies:
21
21
  version: 4.8.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70118988773040
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 4.8.1
25
30
  - !ruby/object:Gem::Dependency
26
- name: rb-fsevent
27
- requirement: &70118988769120 !ruby/object:Gem::Requirement
31
+ name: listen
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: 0.4.3.1
37
+ version: 1.0.2
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70118988769120
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.2
36
46
  description: ! 'description: rego kicks the ass'
37
47
  email: ara.t.howard@gmail.com
38
48
  executables:
@@ -65,8 +75,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
75
  version: '0'
66
76
  requirements: []
67
77
  rubyforge_project: codeforpeople
68
- rubygems_version: 1.8.11
78
+ rubygems_version: 1.8.23
69
79
  signing_key:
70
80
  specification_version: 3
71
81
  summary: rego
72
82
  test_files: []
83
+ has_rdoc: