judges 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1b1028f7e8d932c33c2f0c761ede5fa5478a913d2292f56a70fe7ff0e8902aa
4
- data.tar.gz: 0a48c55211f32ce7825a72f67c6c6f3757a3bdc6cf9067b1375712b6e5a3aba6
3
+ metadata.gz: 921a2ee75d8305caea875d0ed79fcbd6b45edc165a7ddb6d8f049a66c489146e
4
+ data.tar.gz: 73176a8f9b99a4aad3ab987f611468b3ca26b47bcc7a9048c4890a76f22e0d7b
5
5
  SHA512:
6
- metadata.gz: e497c35fb9aee490a9c85c911a195414c3ad17a60b60b0b4be0851b6b68a857f879fe66e16b0603db26c8ee0a85af910a15b919e89b997935de5118f288ca180
7
- data.tar.gz: 6894d6010bbbf1f99de4c721821a6d449ca4a15fed9602751b9fa857865c37d730014e9cca48460357c2e8754873077876ca7983ef013c93f78428d77b50ff49
6
+ metadata.gz: 567a566e23353d7cf625b117f733379543a24725456f13c0f5aa680abfc08732c7074e2159368ecf4a7c90e2615a0a72a32e88819f195bea9f2bc93ed9ed80cb
7
+ data.tar.gz: 1294c1cd68138b2e39a632b51e913ac0cb1e8e539f32f7ea3067339a946ce93ea6c27356d45ea375d8fd8d42b396f24a4ca2b868d05707c4140d5d4c47a4b866
data/bin/judges CHANGED
@@ -29,13 +29,15 @@ require 'factbase'
29
29
  Encoding.default_external = Encoding::UTF_8
30
30
  Encoding.default_internal = Encoding::UTF_8
31
31
 
32
+ ver = '0.0.15'
33
+
32
34
  include GLI::App
33
35
 
34
36
  loog = Loog::REGULAR
35
37
 
36
38
  program_desc('Automated executor of judges for a factbase')
37
39
 
38
- version('0.0.13')
40
+ version(ver)
39
41
 
40
42
  synopsis_format(:full)
41
43
 
@@ -48,13 +50,14 @@ pre do |global, command, options, args|
48
50
  if global[:verbose]
49
51
  loog = Loog::VERBOSE
50
52
  end
53
+ loog.debug("judges #{ver}")
51
54
  true
52
55
  end
53
56
 
54
57
  desc 'Update the factbase by passing all judges one by one'
55
58
  command :update do |c|
56
59
  c.desc 'Options to pass to every judge'
57
- c.flag([:o, :option], default_value: 'yes', type: Array, arg_name: '<key=value>')
60
+ c.flag([:o, :option], multiple: true, arg_name: '<key=value>')
58
61
  c.action do |global, options, args|
59
62
  require_relative '../lib/judges/commands/update'
60
63
  Judges::Update.new(loog).run(options, args)
data/features/cli.feature CHANGED
@@ -19,7 +19,9 @@ Feature: Simple Run
19
19
  n.kind = 'yes!'
20
20
  end
21
21
  """
22
- Then I run bin/judges with "update . simple.fb"
22
+ Then I run bin/judges with "--verbose update -o foo=1 -o bar=2 . simple.fb"
23
+ Then Stdout contains "foo → "
24
+ Then Stdout contains "bar → "
23
25
  Then Stdout contains "1 judges processed"
24
26
  And Exit code is zero
25
27
 
data/judges.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
27
  s.required_ruby_version = '>=3.2'
28
28
  s.name = 'judges'
29
- s.version = '0.0.13'
29
+ s.version = '0.0.15'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description = '
@@ -43,11 +43,11 @@ class Judges::Join
43
43
  slave = args[1]
44
44
  raise "The slave factbase is absent: #{slave.to_rel}" unless File.exist?(slave)
45
45
  fb = Factbase.new
46
- fb.import(File.read(master))
46
+ fb.import(File.binread(master))
47
47
  @loog.info("Master factbase imported from #{master.to_rel} (#{File.size(master)} bytes)")
48
- fb.import(File.read(slave))
48
+ fb.import(File.binread(slave))
49
49
  @loog.info("Slave factbase imported from #{slave.to_rel} (#{File.size(slave)} bytes)")
50
- File.write(master, fb.export)
50
+ File.binwrite(master, fb.export)
51
51
  @loog.info("Master factbase exported to #{master.to_rel} (#{File.size(master)} bytes)")
52
52
  end
53
53
  end
@@ -46,7 +46,7 @@ class Judges::Print
46
46
  o = "#{o}.#{opts[:format]}"
47
47
  end
48
48
  fb = Factbase.new
49
- fb.import(File.read(f))
49
+ fb.import(File.binread(f))
50
50
  @loog.info("Factbase imported from #{f.to_rel} (#{File.size(f)} bytes)")
51
51
  FileUtils.mkdir_p(File.dirname(o))
52
52
  output =
@@ -58,7 +58,7 @@ class Judges::Print
58
58
  when 'xml'
59
59
  fb.to_xml
60
60
  end
61
- File.write(o, output)
61
+ File.binwrite(o, output)
62
62
  @loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)")
63
63
  end
64
64
  end
@@ -40,11 +40,11 @@ class Judges::Update
40
40
  def run(opts, args)
41
41
  raise 'Exactly two arguments required' unless args.size == 2
42
42
  dir = args[0]
43
- raise "The directory is absent: #{dir}" unless File.exist?(dir)
43
+ raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir)
44
44
  file = args[1]
45
45
  fb = Factbase.new
46
46
  if File.exist?(file)
47
- fb.import(File.read(file))
47
+ fb.import(File.binread(file))
48
48
  @loog.info("Factbase imported from #{file.to_rel} (#{File.size(file)} bytes)")
49
49
  else
50
50
  @loog.info("There is no Factbase to import from #{file.to_rel} (file is absent)")
@@ -53,17 +53,20 @@ class Judges::Update
53
53
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
54
54
  errors = []
55
55
  done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
56
- @loog.info("Pack ##{i} found in #{p.dir.to_rel}")
56
+ @loog.info("Running #{p.dir.to_rel} (##{i})...")
57
+ before = fb.size
57
58
  begin
58
59
  p.run(fb, options)
59
60
  rescue StandardError => e
60
61
  @loog.warn(Backtrace.new(e))
61
62
  errors << p.script
62
63
  end
64
+ after = fb.size
65
+ @loog.info("Pack #{p.dir.to_rel} added #{after - before} facts") if after > before
63
66
  end
64
67
  @loog.info("#{done} judges processed (#{errors.size} errors)")
65
68
  FileUtils.mkdir_p(File.dirname(file))
66
- File.write(file, fb.export)
69
+ File.binwrite(file, fb.export)
67
70
  @loog.info("Factbase exported to #{file.to_rel} (#{File.size(file)} bytes)")
68
71
  raise "Failed to update correctly (#{errors.size} errors)" unless errors.empty?
69
72
  end
@@ -39,7 +39,7 @@ class Judges::Options
39
39
  @hash.map do |k, v|
40
40
  v = v.to_s
41
41
  v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
42
- "#{k}=#{v}"
42
+ "#{k} → \"#{v}\""
43
43
  end.join("\n")
44
44
  end
45
45
 
@@ -49,6 +49,8 @@ class Judges::Options
49
49
  pp = @pairs || []
50
50
  pp = @pairs.map { |k, v| "#{k}=#{v}" } if pp.is_a?(Hash)
51
51
  pp = pp.split(',') if pp.is_a?(String)
52
+ pp.compact!
53
+ pp.reject!(&:empty?)
52
54
  pp.to_h do |pair|
53
55
  p = pair.split('=', 2)
54
56
  k = p[0].strip
data/lib/judges/to_rel.rb CHANGED
@@ -32,6 +32,7 @@ class Object
32
32
  s = File.absolute_path(to_s)
33
33
  p = Pathname.new(s).relative_path_from(Dir.getwd)
34
34
  t = p.to_s
35
+ t = s if t.length > s.length
35
36
  t = "\"#{t}\"" if t.include?(' ')
36
37
  if p.directory?
37
38
  "#{t}/"
@@ -36,14 +36,14 @@ class TestJoin < Minitest::Test
36
36
  master = File.join(d, 'master.fb')
37
37
  fb1 = Factbase.new
38
38
  fb1.insert.zz = 5
39
- File.write(master, fb1.export)
39
+ File.binwrite(master, fb1.export)
40
40
  slave = File.join(d, 'slave.fb')
41
41
  fb2 = Factbase.new
42
42
  fb2.insert.foo_bar = 42
43
- File.write(slave, fb2.export)
43
+ File.binwrite(slave, fb2.export)
44
44
  Judges::Join.new(Loog::VERBOSE).run({}, [master, slave])
45
45
  fb = Factbase.new
46
- fb.import(File.read(master))
46
+ fb.import(File.binread(master))
47
47
  xml = Nokogiri::XML.parse(fb.to_xml)
48
48
  assert(!xml.xpath('/fb/f[zz="5"]').empty?, fb.to_xml)
49
49
  assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, fb.to_xml)
@@ -37,7 +37,7 @@ class TestPrint < Minitest::Test
37
37
  f = File.join(d, 'base.fb')
38
38
  fb = Factbase.new
39
39
  fb.insert
40
- File.write(f, fb.export)
40
+ File.binwrite(f, fb.export)
41
41
  Judges::Print.new(Loog::VERBOSE).run({ format: 'yaml', auto: true }, [f])
42
42
  y = File.join(d, 'base.yaml')
43
43
  assert(File.exist?(y))
@@ -37,7 +37,7 @@ class TestUpdate < Minitest::Test
37
37
  file = File.join(d, 'base.fb')
38
38
  Judges::Update.new(Loog::VERBOSE).run({ 'option' => ['foo_bar=42'] }, [d, file])
39
39
  fb = Factbase.new
40
- fb.import(File.read(file))
40
+ fb.import(File.binread(file))
41
41
  xml = Nokogiri::XML.parse(fb.to_xml)
42
42
  assert(!xml.xpath('/fb/f[zzz="43"]').empty?)
43
43
  end
@@ -48,11 +48,11 @@ class TestUpdate < Minitest::Test
48
48
  file = File.join(d, 'base.fb')
49
49
  fb = Factbase.new
50
50
  fb.insert.foo_bar = 42
51
- File.write(file, fb.export)
51
+ File.binwrite(file, fb.export)
52
52
  File.write(File.join(d, 'foo.rb'), '$fb.insert.tt = 4')
53
53
  Judges::Update.new(Loog::VERBOSE).run({}, [d, file])
54
54
  fb = Factbase.new
55
- fb.import(File.read(file))
55
+ fb.import(File.binread(file))
56
56
  xml = Nokogiri::XML.parse(fb.to_xml)
57
57
  assert(!xml.xpath('/fb/f[tt="4"]').empty?)
58
58
  assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?)
data/test/test_options.rb CHANGED
@@ -46,6 +46,16 @@ class TestOptions < Minitest::Test
46
46
  assert(opts.foo.nil?)
47
47
  end
48
48
 
49
+ def test_with_empty_string
50
+ opts = Judges::Options.new(' ')
51
+ assert(opts.foo.nil?)
52
+ end
53
+
54
+ def test_with_empty_strings
55
+ opts = Judges::Options.new(['', nil])
56
+ assert(opts.foo.nil?)
57
+ end
58
+
49
59
  def test_with_string
50
60
  opts = Judges::Options.new('a=1,b=42')
51
61
  assert_equal(1, opts.a)
@@ -61,6 +71,8 @@ class TestOptions < Minitest::Test
61
71
 
62
72
  def test_converts_to_string
63
73
  opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
64
- assert_equal("foo=44\nbar=long********************", opts.to_s)
74
+ s = opts.to_s
75
+ assert(s.include?('foo → "44"'))
76
+ assert(s.include?('"long********************"'))
65
77
  end
66
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko