judges 0.0.13 → 0.0.14

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: e45e98c063327eedc9ae2731bb8c8c39358291ca8c687f6cf37997df37cf84aa
4
+ data.tar.gz: 811ae41514764e68e9cc4fa0a3ea0429bed9128eec2142268e4cdb779ce12b5e
5
5
  SHA512:
6
- metadata.gz: e497c35fb9aee490a9c85c911a195414c3ad17a60b60b0b4be0851b6b68a857f879fe66e16b0603db26c8ee0a85af910a15b919e89b997935de5118f288ca180
7
- data.tar.gz: 6894d6010bbbf1f99de4c721821a6d449ca4a15fed9602751b9fa857865c37d730014e9cca48460357c2e8754873077876ca7983ef013c93f78428d77b50ff49
6
+ metadata.gz: 0414dfaa83953985ce7186c336eac2c1a53e71f88c73f9b89c8f1410208191c5d1ff106d91045fa7c6f6f0dd9eb59ed8c189138b51d4b546d5a0a9bbe4211546
7
+ data.tar.gz: d3b3e538af3fa858fd19d67afe3f4b10942c97befa99538fceefcb3eef770cb130bbb1631160191d4e7bac47c0dbe62a184959ba3f1c29956bdf86708f88eefe
data/bin/judges CHANGED
@@ -35,7 +35,7 @@ loog = Loog::REGULAR
35
35
 
36
36
  program_desc('Automated executor of judges for a factbase')
37
37
 
38
- version('0.0.13')
38
+ version('0.0.14')
39
39
 
40
40
  synopsis_format(:full)
41
41
 
@@ -54,7 +54,7 @@ end
54
54
  desc 'Update the factbase by passing all judges one by one'
55
55
  command :update do |c|
56
56
  c.desc 'Options to pass to every judge'
57
- c.flag([:o, :option], default_value: 'yes', type: Array, arg_name: '<key=value>')
57
+ c.flag([:o, :option], multiple: true, arg_name: '<key=value>')
58
58
  c.action do |global, options, args|
59
59
  require_relative '../lib/judges/commands/update'
60
60
  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.14'
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
 
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
@@ -61,6 +61,8 @@ class TestOptions < Minitest::Test
61
61
 
62
62
  def test_converts_to_string
63
63
  opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
64
- assert_equal("foo=44\nbar=long********************", opts.to_s)
64
+ s = opts.to_s
65
+ assert(s.include?('foo → "44"'))
66
+ assert(s.include?('"long********************"'))
65
67
  end
66
68
  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.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko