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