rego 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +147 -159
  3. data/bin/rego +82 -175
  4. data/lib/rego/_lib.rb +12 -12
  5. data/lib/rego/utils.rb +40 -33
  6. data/lib/rego.rb +3 -2
  7. data/rego.gemspec +5 -16
  8. metadata +12 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb49b3d2016108b3dec5ada89bc0e68ab2a5910845a629926929f10510a62f2c
4
- data.tar.gz: 27aac62ef93b549bb813978e17b1202c8b5af1ce06c4324fed147bcebbdc4bc2
3
+ metadata.gz: 109c640a020a86cc42d4713fba6d20e91d5e287d4e51c9741c28ffc85b014161
4
+ data.tar.gz: 5b49788c8776d6447aba2403a2ae351eb936630c919c27dce7ed38542fa5a5b7
5
5
  SHA512:
6
- metadata.gz: 9e4ae3bf5f6947650575517dc3d679983e119e724f50f9edf5e6474d850067439766633b2022a0c706d226ff4f4aeb89b85f18d8979d76eaaacb1a27f25f6dee
7
- data.tar.gz: a9e310138224b88f4f4b3a9858a3a3dd3517f97c7525884a4a521d50e27425d72c0a7ecdda004aab34fd98b1a68ae90226384764d87ccf995c0c93d71eff7052
6
+ metadata.gz: 00d6c2e1ed14a6e74a285f1f707508c2b50646de0bdbfaa5bbacea0b1798c4baec145beb4bb5e93c41f4f5910eec14d0a1ede8648bb8edf196e2e5ca2ad47eee
7
+ data.tar.gz: 01a24a9972e11e6125901e043e0d63f2b972d3d505e612344ee345115e910602549e8f289242f3a16507705d055b11766280150065ffa63fbe0093e6f5b1c4d9
data/Rakefile CHANGED
@@ -1,14 +1,13 @@
1
- This.rubyforge_project = 'codeforpeople'
2
- This.author = "Ara T. Howard"
3
- This.email = "ara.t.howard@gmail.com"
4
- This.homepage = "https://github.com/ahoward/#{ This.lib }"
1
+ This.author = 'Ara T. Howard'
2
+ This.email = 'ara.t.howard@gmail.com'
3
+ This.homepage = "https://github.com/ahoward/#{This.lib}"
5
4
 
6
5
  task :license do
7
- open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
6
+ open('LICENSE', 'w') { |fd| fd.puts 'Ruby' }
8
7
  end
9
8
 
10
9
  task :default do
11
- puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
10
+ puts((Rake::Task.tasks.map { |task| task.name.gsub(/::/, ':') } - ['default']).sort)
12
11
  end
13
12
 
14
13
  task :test do
@@ -16,90 +15,92 @@ task :test do
16
15
  end
17
16
 
18
17
  namespace :test do
19
- task(:unit){ run_tests!(:unit) }
20
- task(:functional){ run_tests!(:functional) }
21
- task(:integration){ run_tests!(:integration) }
18
+ task(:unit) { run_tests!(:unit) }
19
+ task(:functional) { run_tests!(:functional) }
20
+ task(:integration) { run_tests!(:integration) }
22
21
  end
23
22
 
24
23
  def run_tests!(which = nil)
25
24
  which ||= '**'
26
- test_dir = File.join(This.dir, "test")
27
- test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
25
+ test_dir = File.join(This.dir, 'test')
26
+ test_glob ||= File.join(test_dir, "#{which}/**_test.rb")
28
27
  test_rbs = Dir.glob(test_glob).sort
29
-
28
+
30
29
  div = ('=' * 119)
31
30
  line = ('-' * 119)
32
31
 
33
32
  test_rbs.each_with_index do |test_rb, index|
34
33
  testno = index + 1
35
- command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
34
+ command = "#{This.ruby} -w -I ./lib -I ./test/lib #{test_rb}"
36
35
 
37
36
  puts
38
- say(div, :color => :cyan, :bold => true)
39
- say("@#{ testno } => ", :bold => true, :method => :print)
40
- say(command, :color => :cyan, :bold => true)
41
- say(line, :color => :cyan, :bold => true)
37
+ say(div, color: :cyan, bold: true)
38
+ say("@#{testno} => ", bold: true, method: :print)
39
+ say(command, color: :cyan, bold: true)
40
+ say(line, color: :cyan, bold: true)
42
41
 
43
42
  system(command)
44
43
 
45
- say(line, :color => :cyan, :bold => true)
44
+ say(line, color: :cyan, bold: true)
46
45
 
47
46
  status = $?.exitstatus
48
47
 
49
- if status.zero?
50
- say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
51
- say("SUCCESS", :color => :green, :bold => true)
48
+ if status.zero?
49
+ say("@#{testno} <= ", bold: true, color: :white, method: :print)
50
+ say('SUCCESS', color: :green, bold: true)
52
51
  else
53
- say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
54
- say("FAILURE", :color => :red, :bold => true)
52
+ say("@#{testno} <= ", bold: true, color: :white, method: :print)
53
+ say('FAILURE', color: :red, bold: true)
55
54
  end
56
- say(line, :color => :cyan, :bold => true)
55
+ say(line, color: :cyan, bold: true)
57
56
 
58
57
  exit(status) unless status.zero?
59
58
  end
60
59
  end
61
60
 
62
-
63
61
  task :gemspec do
64
62
  ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
65
63
  ignore_directories = ['pkg']
66
64
  ignore_files = ['test/log']
67
65
 
68
- shiteless =
66
+ shiteless =
69
67
  lambda do |list|
70
68
  list.delete_if do |entry|
71
- next unless test(?e, entry)
72
- extension = File.basename(entry).split(%r/[.]/).last
73
- ignore_extensions.any?{|ext| ext === extension}
69
+ next unless test('e', entry)
70
+
71
+ extension = File.basename(entry).split(/[.]/).last
72
+ ignore_extensions.any? { |ext| ext === extension }
74
73
  end
75
74
  list.delete_if do |entry|
76
- next unless test(?d, entry)
75
+ next unless test('d', entry)
76
+
77
77
  dirname = File.expand_path(entry)
78
- ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
78
+ ignore_directories.any? { |dir| File.expand_path(dir) == dirname }
79
79
  end
80
80
  list.delete_if do |entry|
81
- next unless test(?f, entry)
81
+ next unless test('f', entry)
82
+
82
83
  filename = File.expand_path(entry)
83
- ignore_files.any?{|file| File.expand_path(file) == filename}
84
+ ignore_files.any? { |file| File.expand_path(file) == filename }
84
85
  end
85
86
  end
86
87
 
87
88
  lib = This.lib
88
89
  object = This.object
89
90
  version = This.version
90
- files = shiteless[Dir::glob("**/**")]
91
- executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
92
- #has_rdoc = true #File.exist?('doc')
93
- test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
94
- summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
95
- description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
96
- license = object.respond_to?(:license) ? object.license : "Ruby"
91
+ files = shiteless[Dir.glob('**/**')]
92
+ executables = shiteless[Dir.glob('bin/*')].map { |exe| File.basename(exe) }
93
+ # has_rdoc = true #File.exist?('doc')
94
+ test_files = "test/#{lib}.rb" if File.file?("test/#{lib}.rb")
95
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{lib} kicks the ass"
96
+ description = object.respond_to?(:description) ? object.description : "description: #{lib} kicks the ass"
97
+ license = object.respond_to?(:license) ? object.license : 'Ruby'
97
98
 
98
99
  if This.extensions.nil?
99
100
  This.extensions = []
100
101
  extensions = This.extensions
101
- %w( Makefile configure extconf.rb ).each do |ext|
102
- extensions << ext if File.exists?(ext)
102
+ %w[Makefile configure extconf.rb].each do |ext|
103
+ extensions << ext if File.exist?(ext)
103
104
  end
104
105
  end
105
106
  extensions = [extensions].flatten.compact
@@ -108,18 +109,18 @@ task :gemspec do
108
109
  dependencies = []
109
110
  else
110
111
  case This.dependencies
111
- when Hash
112
- dependencies = This.dependencies.values
113
- when Array
114
- dependencies = This.dependencies
112
+ when Hash
113
+ dependencies = This.dependencies.values
114
+ when Array
115
+ dependencies = This.dependencies
115
116
  end
116
117
  end
117
118
 
118
- template =
119
- if test(?e, 'gemspec.erb')
120
- Template{ IO.read('gemspec.erb') }
119
+ template =
120
+ if test('e', 'gemspec.erb')
121
+ Template { IO.read('gemspec.erb') }
121
122
  else
122
- Template {
123
+ Template do
123
124
  <<-__
124
125
  ## <%= lib %>.gemspec
125
126
  #
@@ -132,9 +133,9 @@ task :gemspec do
132
133
  spec.description = <%= description.inspect %>
133
134
  spec.license = <%= license.inspect %>
134
135
 
135
- spec.files =\n<%= files.sort.pretty_inspect %>
136
+ spec.files =\n<%= files.sort.inspect %>
136
137
  spec.executables = <%= executables.inspect %>
137
-
138
+ #{' '}
138
139
  spec.require_path = "lib"
139
140
 
140
141
  spec.test_files = <%= test_files.inspect %>
@@ -145,26 +146,25 @@ task :gemspec do
145
146
 
146
147
  spec.extensions.push(*<%= extensions.inspect %>)
147
148
 
148
- spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
149
149
  spec.author = <%= This.author.inspect %>
150
150
  spec.email = <%= This.email.inspect %>
151
151
  spec.homepage = <%= This.homepage.inspect %>
152
152
  end
153
153
  __
154
- }
154
+ end
155
155
  end
156
156
 
157
157
  Fu.mkdir_p(This.pkgdir)
158
- gemspec = "#{ lib }.gemspec"
159
- open(gemspec, "w"){|fd| fd.puts(template)}
158
+ gemspec = "#{lib}.gemspec"
159
+ open(gemspec, 'w') { |fd| fd.puts(template) }
160
160
  This.gemspec = gemspec
161
161
  end
162
162
 
163
- task :gem => [:clean, :gemspec] do
163
+ task gem: %i[clean gemspec] do
164
164
  Fu.mkdir_p(This.pkgdir)
165
165
  before = Dir['*.gem']
166
- cmd = "gem build #{ This.gemspec }"
167
- `#{ cmd }`
166
+ cmd = "gem build #{This.gemspec}"
167
+ `#{cmd}`
168
168
  after = Dir['*.gem']
169
169
  gem = ((after - before).first || after.first) or abort('no gem!')
170
170
  Fu.mv(gem, This.pkgdir)
@@ -178,87 +178,74 @@ task :readme do
178
178
  version = This.version
179
179
 
180
180
  Dir['sample*/*'].sort.each do |sample|
181
- samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
181
+ samples << "\n" << " <========< #{sample} >========>" << "\n\n"
182
182
 
183
- cmd = "cat #{ sample }"
183
+ cmd = "cat #{sample}"
184
184
  samples << Util.indent(prompt + cmd, 2) << "\n\n"
185
- samples << Util.indent(`#{ cmd }`, 4) << "\n"
185
+ samples << Util.indent(`#{cmd}`, 4) << "\n"
186
186
 
187
- cmd = "ruby #{ sample }"
187
+ cmd = "ruby #{sample}"
188
188
  samples << Util.indent(prompt + cmd, 2) << "\n\n"
189
189
 
190
- cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
191
- samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
190
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{sample})'"
191
+ samples << Util.indent(`#{cmd} 2>&1`, 4) << "\n"
192
192
  end
193
193
 
194
- template =
195
- if test(?e, 'README.erb')
196
- Template{ IO.read('README.erb') }
194
+ template =
195
+ if test('e', 'README.erb')
196
+ Template { IO.read('README.erb') }
197
197
  else
198
- Template {
198
+ Template do
199
199
  <<-__
200
200
  NAME
201
- #{ lib }
201
+ #{lib}
202
202
 
203
203
  DESCRIPTION
204
204
 
205
205
  INSTALL
206
- gem install #{ lib }
206
+ gem install #{lib}
207
207
 
208
208
  SAMPLES
209
- #{ samples }
209
+ #{samples}
210
210
  __
211
- }
211
+ end
212
212
  end
213
213
 
214
- open("README", "w"){|fd| fd.puts template}
214
+ open('README', 'w') { |fd| fd.puts template }
215
215
  end
216
216
 
217
-
218
217
  task :clean do
219
- Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
218
+ Dir[File.join(This.pkgdir, '**/**')].each { |entry| Fu.rm_rf(entry) }
220
219
  end
221
220
 
222
-
223
- task :release => [:clean, :gemspec, :gem] do
221
+ task release: %i[clean gemspec gem] do
224
222
  gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
225
- raise "which one? : #{ gems.inspect }" if gems.size > 1
226
- raise "no gems?" if gems.size < 1
227
-
228
- cmd = "gem push #{ This.gem }"
229
- puts cmd
230
- puts
231
- system(cmd)
232
- abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
223
+ raise "which one? : #{gems.inspect}" if gems.size > 1
224
+ raise 'no gems?' if gems.size < 1
233
225
 
234
- cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
226
+ cmd = "gem push #{This.gem}"
235
227
  puts cmd
236
228
  puts
237
229
  system(cmd)
238
- abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
230
+ abort("cmd(#{cmd}) failed with (#{$?.inspect})") unless $?.exitstatus.zero?
239
231
  end
240
232
 
241
-
242
-
243
-
244
-
245
233
  BEGIN {
246
- # support for this rakefile
247
- #
234
+ # support for this rakefile
235
+ #
248
236
  $VERBOSE = nil
249
237
 
250
238
  require 'ostruct'
251
239
  require 'erb'
252
240
  require 'fileutils'
253
241
  require 'rbconfig'
254
- require 'pp'
255
242
 
256
- # fu shortcut
257
- #
243
+ # fu shortcut
244
+ #
258
245
  Fu = FileUtils
259
246
 
260
- # cache a bunch of stuff about this rakefile/environment
261
- #
247
+ # cache a bunch of stuff about this rakefile/environment
248
+ #
262
249
  This = OpenStruct.new
263
250
 
264
251
  This.file = File.expand_path(__FILE__)
@@ -266,115 +253,116 @@ BEGIN {
266
253
  This.pkgdir = File.join(This.dir, 'pkg')
267
254
 
268
255
  This.lib = File.basename(Dir.pwd)
269
- This._lib = "#{ This.dir }/lib/#{ This.lib }/_lib.rb"
256
+ This._lib = "#{This.dir}/lib/#{This.lib}/_lib.rb"
270
257
 
271
- # load meta lib info
272
- #
258
+ # load meta lib info
259
+ #
273
260
  a = Object.constants.dup
274
261
  require This._lib
275
262
  b = Object.constants.dup
276
263
  added = b - a
277
264
  const = added.first
278
265
 
279
- if added.size > 1
280
- STDERR.puts "WARNING: defined multiple constants #{ added.inspect } in #{ _lib }, using #{ const } !!!"
281
- end
266
+ warn "WARNING: defined multiple constants #{added.inspect} in #{_lib}, using #{const} !!!" if added.size > 1
282
267
 
283
268
  This.const = const
284
269
  This.object = Object.const_get(This.const)
285
270
  This.name = This.object.name
286
271
  This.version = This.object.send(:version)
287
272
 
288
- # see if dependencies are export by the module
289
- #
290
- if This.object.respond_to?(:dependencies)
291
- This.dependencies = This.object.dependencies
292
- end
273
+ # see if dependencies are export by the module
274
+ #
275
+ This.dependencies = This.object.dependencies if This.object.respond_to?(:dependencies)
293
276
 
294
- # we need to know the name of the lib an it's version
295
- #
277
+ # we need to know the name of the lib an it's version
278
+ #
296
279
  abort('no lib') unless This.lib
297
280
  abort('no version') unless This.version
298
281
 
299
- # discover full path to this ruby executable
300
- #
282
+ # discover full path to this ruby executable
283
+ #
301
284
  c = RbConfig::CONFIG
302
- bindir = c["bindir"] || c['BINDIR']
285
+ bindir = c['bindir'] || c['BINDIR']
303
286
  ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
304
287
  ruby_ext = c['EXEEXT'] || ''
305
288
  ruby = File.join(bindir, (ruby_install_name + ruby_ext))
306
289
  This.ruby = ruby
307
290
 
308
- # some utils
309
- #
291
+ # some utils
292
+ #
310
293
  module Util
311
294
  def indent(s, n = 2)
312
295
  s = unindent(s)
313
296
  ws = ' ' * n
314
- s.gsub(%r/^/, ws)
297
+ s.gsub(/^/, ws)
315
298
  end
316
299
 
317
300
  def unindent(s)
318
301
  indent = nil
319
302
  s.each_line do |line|
320
- next if line =~ %r/^\s*$/
321
- indent = line[%r/^\s*/] and break
303
+ next if line =~ /^\s*$/
304
+
305
+ indent = line[/^\s*/] and break
306
+ end
307
+ indent ? s.gsub(/^#{indent}/, '') : s
322
308
  end
323
- indent ? s.gsub(%r/^#{ indent }/, "") : s
324
- end
325
309
  extend self
326
310
  end
327
311
 
328
- # template support
329
- #
312
+ # template support
313
+ #
330
314
  class Template
331
315
  def initialize(&block)
332
316
  @block = block
333
317
  @template = block.call.to_s
334
318
  end
335
- def expand(b=nil)
336
- ERB.new(Util.unindent(@template)).result((b||@block).binding)
319
+
320
+ def expand(b = nil)
321
+ ERB.new(Util.unindent(@template)).result((b || @block).binding)
337
322
  end
338
323
  alias_method 'to_s', 'expand'
339
324
  end
340
- def Template(*args, &block) Template.new(*args, &block) end
341
325
 
342
- # colored console output support
343
- #
326
+ def Template(*args, &block)
327
+ Template.new(*args, &block)
328
+ end
329
+
330
+ # colored console output support
331
+ #
344
332
  This.ansi = {
345
- :clear => "\e[0m",
346
- :reset => "\e[0m",
347
- :erase_line => "\e[K",
348
- :erase_char => "\e[P",
349
- :bold => "\e[1m",
350
- :dark => "\e[2m",
351
- :underline => "\e[4m",
352
- :underscore => "\e[4m",
353
- :blink => "\e[5m",
354
- :reverse => "\e[7m",
355
- :concealed => "\e[8m",
356
- :black => "\e[30m",
357
- :red => "\e[31m",
358
- :green => "\e[32m",
359
- :yellow => "\e[33m",
360
- :blue => "\e[34m",
361
- :magenta => "\e[35m",
362
- :cyan => "\e[36m",
363
- :white => "\e[37m",
364
- :on_black => "\e[40m",
365
- :on_red => "\e[41m",
366
- :on_green => "\e[42m",
367
- :on_yellow => "\e[43m",
368
- :on_blue => "\e[44m",
369
- :on_magenta => "\e[45m",
370
- :on_cyan => "\e[46m",
371
- :on_white => "\e[47m"
333
+ clear: "\e[0m",
334
+ reset: "\e[0m",
335
+ erase_line: "\e[K",
336
+ erase_char: "\e[P",
337
+ bold: "\e[1m",
338
+ dark: "\e[2m",
339
+ underline: "\e[4m",
340
+ underscore: "\e[4m",
341
+ blink: "\e[5m",
342
+ reverse: "\e[7m",
343
+ concealed: "\e[8m",
344
+ black: "\e[30m",
345
+ red: "\e[31m",
346
+ green: "\e[32m",
347
+ yellow: "\e[33m",
348
+ blue: "\e[34m",
349
+ magenta: "\e[35m",
350
+ cyan: "\e[36m",
351
+ white: "\e[37m",
352
+ on_black: "\e[40m",
353
+ on_red: "\e[41m",
354
+ on_green: "\e[42m",
355
+ on_yellow: "\e[43m",
356
+ on_blue: "\e[44m",
357
+ on_magenta: "\e[45m",
358
+ on_cyan: "\e[46m",
359
+ on_white: "\e[47m"
372
360
  }
373
361
  def say(phrase, *args)
374
362
  options = args.last.is_a?(Hash) ? args.pop : {}
375
363
  options[:color] = args.shift.to_s.to_sym unless args.empty?
376
364
  keys = options.keys
377
- keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
365
+ keys.each { |key| options[key.to_s.to_sym] = options.delete(key) }
378
366
 
379
367
  color = options[:color]
380
368
  bold = options.has_key?(:bold)
@@ -389,7 +377,7 @@ BEGIN {
389
377
  Kernel.send(method, parts.join)
390
378
  end
391
379
 
392
- # always run out of the project dir
393
- #
380
+ # always run out of the project dir
381
+ #
394
382
  Dir.chdir(This.dir)
395
383
  }
data/bin/rego CHANGED
@@ -1,24 +1,15 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- Main {
3
+ Main do
4
+ name 'rego'
4
5
 
5
- name <<-__
6
-
7
- rego
8
-
9
- __
6
+ version Rego.version
10
7
 
11
8
  description <<-__
12
-
13
9
  run arbitrary commands easily when files change
14
-
15
10
  __
16
11
 
17
12
  examples <<-__
18
-
19
- ### gem install rego
20
-
21
-
22
13
  # say hai whenever the file foo.txt changes
23
14
  #
24
15
  ~> rego foo.txt -- echo hai
@@ -40,212 +31,128 @@ Main {
40
31
  ~> rego ./test -- ruby -Itest @
41
32
  __
42
33
 
43
- option('--replacement=replacement', '-r'){
44
- default '@'
45
- }
46
-
47
- option('--no-replacement', '-n'){
48
- }
34
+ option('--path=path', '-p')
35
+ option('--paths=paths')
36
+ option('--command=command', '-c')
49
37
 
50
38
  def run
51
- parse_the_command_line
52
- print_a_summary_of_watched_files
53
- loop_watching_files_and_running_commands
39
+ parse_the_command_line!
40
+ print_a_summary_of_watched_files!
41
+ loop_watching_files_and_running_commands!
54
42
  end
55
43
 
56
- def parse_the_command_line
57
- # FIXME - this works around main.rb dropping '--' on the floor in @argv so
58
- # we restore it and re-parse params to restore valid state. should be
59
- # forward compatible if main fixes this though...
60
- #
61
- argv, command = ARGV.join(' ').split(/\s+--\s+/).map{|value| value.to_s.strip}
62
- @argv = argv.scan(/[^\s]+/)
63
- parse_parameters()
44
+ def parse_the_command_line!
45
+ @paths = @params[:paths].values + @params[:path].values
46
+ @command = @params[:command].values
47
+
48
+ state = :paths
64
49
 
65
- @replacement = params[:replacement].value
50
+ @argv.each do |arg|
51
+ if arg.strip == '--'
52
+ state = :commands
53
+ next
54
+ end
66
55
 
67
- if params['no-replacement'].given?
68
- @replacement = false
56
+ if state == :paths
57
+ @paths << arg
58
+ else
59
+ @command << arg
60
+ end
69
61
  end
70
62
 
71
- _args, _command = @argv, command
72
- _paths = _args.join(' ').strip.scan(/[^\s]+/)
63
+ @paths.push(Dir.pwd) if @paths.empty?
64
+ @command.push('ls') if @command.empty?
73
65
 
74
- if _paths.empty?
75
- _paths.push '.'
76
- end
66
+ @pretty = {
67
+ command: @command.map { |token| Shellwords.escape(token) }.join(' '),
68
+ paths: @paths.map { |path| Rego.relative_path(path, from: Dir.pwd) }.join(', ')
69
+ }
77
70
 
78
- @paths = _args.join(' ').strip.scan(/[^\s]+/).sort.uniq
79
- @command = _command.to_s.strip
71
+ return unless @paths.empty?
80
72
 
81
- if @command.empty?
82
- @command = false
83
- end
73
+ abort "no paths to watch found in `#{$0} #{@argv.join(' ')}`"
84
74
  end
85
75
 
86
- def print_a_summary_of_watched_files
87
- puts "## #{ @command }"
88
- puts "#"
89
- puts @paths.join("\n")
76
+ def print_a_summary_of_watched_files!
77
+ Rego.say("#=> rego.command: #{@pretty[:command]}", color: :cyan)
78
+ Rego.say("#=> rego.paths: #{@pretty[:paths]}", color: :cyan)
90
79
  puts
91
80
  end
92
81
 
93
- def loop_watching_files_and_running_commands
94
- @initial_directories = []
95
- @directories = []
96
- @files = []
82
+ def loop_watching_files_and_running_commands!
83
+ cmdno = '0'
97
84
 
98
- @paths.each do |path|
99
- if test(?d, path)
100
- @directories.push(Rego.realpath(path))
101
- @initial_directories.push(Rego.realpath(path))
102
- else
103
- @files.push(Rego.realpath(path))
104
- @directories.push(Rego.realpath(File.dirname(path)))
105
- end
106
- end
107
-
108
- @directories.uniq!
109
- @files.uniq!
110
-
111
- stats = {}
112
-
113
- (@directories + @files).each do |file|
114
- begin
115
- stats[file] = File.stat(file)
116
- rescue
117
- nil
118
- end
119
- end
120
-
121
- #
122
- n = '0'
123
- line = '#' * 42
124
- $running = false
125
-
126
- #
127
85
  rego =
128
- proc do |*args|
129
- path = args.flatten.compact.shift.to_s
130
-
131
- cmd =
132
- if @command
133
- @replacement ? @command.gsub(@replacement, path) : @command
134
- else
135
- "echo #{ path.inspect }"
136
- end
137
-
138
- puts line
139
-
140
- Rego.say("# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ cmd }", :color => :magenta)
86
+ proc do
141
87
  puts
88
+ Rego.say("#=> rego.#{cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> #{@pretty[:command]}", color: :yellow)
142
89
 
143
- system(cmd)
90
+ success = system(*@command)
144
91
  puts
145
92
 
146
- Rego.say("# rego.#{ n } @ #{ Time.now.strftime('%H:%M:%S') } - #{ $?.exitstatus }", :color => :yellow)
93
+ Rego.say("#=> rego.#{cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> #{$?.exitstatus}",
94
+ color: (success ? :green : :red))
147
95
  puts
148
96
 
149
- n.succ!
97
+ cmdno.succ!
150
98
  end
151
99
 
152
- #
153
- q = Queue.new
154
-
155
- Thread.new do
156
- loop do
157
- args = q.pop
158
-
159
- begin
160
- rego.call(*args)
161
- rescue Object
162
- end
163
- end
100
+ listener = Listen.to(*@paths) do |_modified, _added, _removed|
101
+ rego.call
164
102
  end
165
103
 
166
- rego.call(:__START__)
167
-
168
- #
169
-
170
- watchlist =
171
- [].tap do |list|
172
- @directories.each do |directory|
173
- list.push directory
174
- end
175
-
176
- @files.each do |file|
177
- list.push File.dirname(file)
178
- end
179
-
180
- list.flatten!
181
- list.sort!
182
- list.uniq!
183
- end
184
-
185
- watching = watchlist.inject(Hash.new){|hash, path| hash.update(path => true)}
186
-
187
- listener = Listen.to(*watchlist) do |modified, added, removed|
188
- paths = [modified, added, removed].flatten.compact.sort.uniq
189
-
190
- paths.each do |path|
191
- q.push(path)
192
- end
104
+ begin
105
+ rego.call
106
+ listener.start
107
+ sleep
108
+ rescue SignalException
109
+ exit(0)
193
110
  end
194
-
195
- listener.start
196
-
197
- sleep
198
111
  end
199
- }
200
-
112
+ end
201
113
 
202
114
  BEGIN {
203
115
  # setup a child process to catch signals and brutally shut down the parent as
204
116
  # a monkey-patch to listen/rb-fsevent's busted ctrl-c handling...
205
117
  #
206
- if false
207
- unless((pid = fork))
208
- ppid = Process.ppid
209
-
210
- begin
211
- trap('SIGINT'){
212
- %w(
213
- SIGTERM SIGINT SIGQUIT SIGKILL
214
- ).each do |signal|
215
-
216
- begin
217
- Process.kill("-#{ signal }", ppid)
218
- rescue Object
219
- nil
220
- end
221
-
222
- sleep(rand)
118
+ unless (pid = fork)
119
+ ppid = Process.ppid
120
+
121
+ begin
122
+ trap('SIGINT') do
123
+ %w[
124
+ SIGTERM SIGINT SIGQUIT SIGKILL
125
+ ].each do |signal|
126
+ begin
127
+ Process.kill("-#{signal}", ppid)
128
+ rescue Object
129
+ nil
223
130
  end
224
- }
225
131
 
226
- loop do
227
- Process.kill(0, ppid)
228
- sleep(1)
132
+ sleep(rand)
229
133
  end
230
- rescue Object => e
231
- exit!(0)
232
134
  end
135
+
136
+ loop do
137
+ Process.kill(0, ppid)
138
+ sleep(1)
139
+ end
140
+ rescue Object => e
141
+ exit!(0)
233
142
  end
234
143
  end
235
144
 
236
- require 'pathname'
237
- require 'thread'
238
- require 'set'
145
+ require 'pathname'
239
146
 
240
- this = Pathname.new(__FILE__).realpath.to_s
241
- bindir = File.dirname(this)
242
- rootdir = File.dirname(bindir)
243
- libdir = File.join(rootdir, 'lib')
244
- rego = File.join(libdir, 'rego.rb')
147
+ this = Pathname.new(__FILE__).realpath.to_s
148
+ bindir = File.dirname(this)
149
+ rootdir = File.dirname(bindir)
150
+ libdir = File.join(rootdir, 'lib')
151
+ lib = File.join(libdir, 'rego.rb')
245
152
 
246
- require(rego)
153
+ require(lib)
247
154
 
248
- STDOUT.sync = true
249
- STDERR.sync = true
250
- STDIN.sync = true
155
+ STDOUT.sync = true
156
+ STDERR.sync = true
157
+ STDIN.sync = true
251
158
  }
data/lib/rego/_lib.rb CHANGED
@@ -1,34 +1,34 @@
1
1
  module Rego
2
- Version = '3.0.0' unless defined?(Version)
2
+ Version = '3.2.0' unless defined?(Version)
3
3
 
4
- def Rego.version
4
+ def self.version
5
5
  Rego::Version
6
6
  end
7
7
 
8
- def Rego.dependencies
8
+ def self.dependencies
9
9
  {
10
- 'main' => [ 'main' , ' ~> 6.0' ] ,
11
- 'map' => [ 'map' , ' ~> 6.6' ] ,
12
- 'listen' => [ 'listen' , '~> 3.0' ] ,
10
+ 'main' => ['main', ' ~> 6.3.0'],
11
+ 'map' => ['map', ' ~> 6.6.0'],
12
+ 'listen' => ['listen', ' ~> 3.8.0']
13
13
  }
14
14
  end
15
15
 
16
- def Rego.libdir(*args, &block)
17
- @libdir ||= File.basename(File.expand_path(__FILE__).sub(/\.rb$/,''))
16
+ def self.libdir(*args, &block)
17
+ @libdir ||= File.basename(File.expand_path(__FILE__).sub(/\.rb$/, ''))
18
18
  args.empty? ? @libdir : File.join(@libdir, *args)
19
19
  ensure
20
20
  if block
21
21
  begin
22
22
  $LOAD_PATH.unshift(@libdir)
23
- block.call()
23
+ block.call
24
24
  ensure
25
- $LOAD_PATH.shift()
25
+ $LOAD_PATH.shift
26
26
  end
27
27
  end
28
28
  end
29
29
 
30
- def Rego.load(*libs)
30
+ def self.load(*libs)
31
31
  libs = libs.join(' ').scan(/[^\s+]+/)
32
- Rego.libdir{ libs.each{|lib| Kernel.load(lib) } }
32
+ Rego.libdir { libs.each { |lib| Kernel.load(lib) } }
33
33
  end
34
34
  end
data/lib/rego/utils.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  module Rego
2
- def Rego.realpath(path)
2
+ def self.realpath(path)
3
3
  Pathname.new(path).realpath.to_s
4
4
  end
5
5
 
6
- def Rego.tmpdir(&block)
7
- tmpdir = File.join(Dir.tmpdir, ['rego', Process.ppid.to_s, Process.pid.to_s, Thread.current.object_id.to_s].join('-') + '.d')
6
+ def self.relative_path(path, options = {})
7
+ path = File.expand_path(String(path))
8
+ relative = File.expand_path(String(options[:from]))
9
+ Pathname.new(path).relative_path_from(Pathname.new(relative)).to_s
10
+ end
11
+
12
+ def self.tmpdir(&block)
13
+ tmpdir = File.join(Dir.tmpdir,
14
+ ['rego', Process.ppid.to_s, Process.pid.to_s, Thread.current.object_id.to_s].join('-') + '.d')
8
15
 
9
16
  FileUtils.mkdir_p(tmpdir)
10
17
 
@@ -13,18 +20,18 @@ module Rego
13
20
  Dir.chdir(tmpdir, &block)
14
21
  ensure
15
22
  FileUtils.rm_rf(tmpdir)
16
- at_exit{ `rm -rf #{ tmpdir }` }
23
+ at_exit { `rm -rf #{tmpdir}` }
17
24
  end
18
25
  else
19
26
  tmpdir
20
27
  end
21
28
  end
22
29
 
23
- def Rego.say(phrase, *args)
30
+ def self.say(phrase, *args)
24
31
  options = args.last.is_a?(Hash) ? args.pop : {}
25
32
  options[:color] = args.shift.to_s.to_sym unless args.empty?
26
33
  keys = options.keys
27
- keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
34
+ keys.each { |key| options[key.to_s.to_sym] = options.delete(key) }
28
35
 
29
36
  color = options[:color]
30
37
  bold = options.has_key?(:bold)
@@ -43,32 +50,32 @@ module Rego
43
50
  end
44
51
 
45
52
  ANSI = {
46
- :clear => "\e[0m",
47
- :reset => "\e[0m",
48
- :erase_line => "\e[K",
49
- :erase_char => "\e[P",
50
- :bold => "\e[1m",
51
- :dark => "\e[2m",
52
- :underline => "\e[4m",
53
- :underscore => "\e[4m",
54
- :blink => "\e[5m",
55
- :reverse => "\e[7m",
56
- :concealed => "\e[8m",
57
- :black => "\e[30m",
58
- :red => "\e[31m",
59
- :green => "\e[32m",
60
- :yellow => "\e[33m",
61
- :blue => "\e[34m",
62
- :magenta => "\e[35m",
63
- :cyan => "\e[36m",
64
- :white => "\e[37m",
65
- :on_black => "\e[40m",
66
- :on_red => "\e[41m",
67
- :on_green => "\e[42m",
68
- :on_yellow => "\e[43m",
69
- :on_blue => "\e[44m",
70
- :on_magenta => "\e[45m",
71
- :on_cyan => "\e[46m",
72
- :on_white => "\e[47m"
53
+ clear: "\e[0m",
54
+ reset: "\e[0m",
55
+ erase_line: "\e[K",
56
+ erase_char: "\e[P",
57
+ bold: "\e[1m",
58
+ dark: "\e[2m",
59
+ underline: "\e[4m",
60
+ underscore: "\e[4m",
61
+ blink: "\e[5m",
62
+ reverse: "\e[7m",
63
+ concealed: "\e[8m",
64
+ black: "\e[30m",
65
+ red: "\e[31m",
66
+ green: "\e[32m",
67
+ yellow: "\e[33m",
68
+ blue: "\e[34m",
69
+ magenta: "\e[35m",
70
+ cyan: "\e[36m",
71
+ white: "\e[37m",
72
+ on_black: "\e[40m",
73
+ on_red: "\e[41m",
74
+ on_green: "\e[42m",
75
+ on_yellow: "\e[43m",
76
+ on_blue: "\e[44m",
77
+ on_magenta: "\e[45m",
78
+ on_cyan: "\e[46m",
79
+ on_white: "\e[47m"
73
80
  }
74
81
  end
data/lib/rego.rb CHANGED
@@ -2,10 +2,11 @@ require 'time'
2
2
  require 'pathname'
3
3
  require 'yaml'
4
4
  require 'tmpdir'
5
+ require 'shellwords'
5
6
 
6
7
  module Rego
7
- require_relative 'rego/_lib.rb'
8
- require_relative 'rego/utils.rb'
8
+ require_relative 'rego/_lib'
9
+ require_relative 'rego/utils'
9
10
  end
10
11
 
11
12
  # gems
data/rego.gemspec CHANGED
@@ -3,24 +3,14 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "rego"
6
- spec.version = "3.0.0"
6
+ spec.version = "3.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
  spec.license = "Ruby"
11
11
 
12
12
  spec.files =
13
- ["README.md",
14
- "Rakefile",
15
- "bin",
16
- "bin/rego",
17
- "lib",
18
- "lib/rego",
19
- "lib/rego.rb",
20
- "lib/rego/_lib.rb",
21
- "lib/rego/utils.rb",
22
- "rego.gemspec"]
23
-
13
+ ["README.md", "Rakefile", "bin", "bin/rego", "lib", "lib/rego", "lib/rego.rb", "lib/rego/_lib.rb", "lib/rego/utils.rb", "rego.gemspec"]
24
14
  spec.executables = ["rego"]
25
15
 
26
16
  spec.require_path = "lib"
@@ -28,16 +18,15 @@ Gem::Specification::new do |spec|
28
18
  spec.test_files = nil
29
19
 
30
20
 
31
- spec.add_dependency(*["main", " ~> 6.0"])
21
+ spec.add_dependency(*["main", " ~> 6.3.0"])
32
22
 
33
- spec.add_dependency(*["map", " ~> 6.6"])
23
+ spec.add_dependency(*["map", " ~> 6.6.0"])
34
24
 
35
- spec.add_dependency(*["listen", "~> 3.0"])
25
+ spec.add_dependency(*["listen", " ~> 3.8.0"])
36
26
 
37
27
 
38
28
  spec.extensions.push(*[])
39
29
 
40
- spec.rubyforge_project = "codeforpeople"
41
30
  spec.author = "Ara T. Howard"
42
31
  spec.email = "ara.t.howard@gmail.com"
43
32
  spec.homepage = "https://github.com/ahoward/rego"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rego
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-30 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: main
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: 6.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: 6.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: map
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.6'
33
+ version: 6.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '6.6'
40
+ version: 6.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: listen
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: 3.8.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: 3.8.0
55
55
  description: 'description: rego kicks the ass'
56
56
  email: ara.t.howard@gmail.com
57
57
  executables:
@@ -70,7 +70,7 @@ homepage: https://github.com/ahoward/rego
70
70
  licenses:
71
71
  - Ruby
72
72
  metadata: {}
73
- post_install_message:
73
+ post_install_message:
74
74
  rdoc_options: []
75
75
  require_paths:
76
76
  - lib
@@ -85,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.0.3
89
- signing_key:
88
+ rubygems_version: 3.4.1
89
+ signing_key:
90
90
  specification_version: 4
91
91
  summary: rego
92
92
  test_files: []