judges 0.0.17 → 0.0.18

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: 7312c2f398cbad4906226fbc64c489a95428281003dcab21988185b214bea734
4
- data.tar.gz: 7ecf453fcef5028bb43219ddfde277bd1e0e3633059afa69bafe895c8b9fa52a
3
+ metadata.gz: 8399b8c8623c0d099deeb50055658e072bae333b0d851cd0aaef22f441655950
4
+ data.tar.gz: c8ef8e75705e8d0cf3bdb8033c054f7ac4c239566bf0cb80b6a9cc0943932986
5
5
  SHA512:
6
- metadata.gz: 8000605816940bd197b284921b1a8218e51537c77f98fd7a932f5f47bac5c366dbe48fa3da0113dfa2db0c3760070d943a5d07a189f29ee87ddb3e0f6cedb18f
7
- data.tar.gz: 9692dc49019dab0d0573cec9a95bbdd611328a7e2d95b3efc12ae5cc2e6a250d1ed2801d0c54b954872f53cf5d00139bf12c514612b8a86be72d18cf6dfd3d5e
6
+ metadata.gz: 7a187a9441700826cf7b539ed264a7d80e5e749169219c62d717cee1451cd77e78f5e9a130617dd2e589ad0c13d504e27482527db2dc6b80da12561ff8d1e3e4
7
+ data.tar.gz: 38c5ae3b4af2981b56d9069a794d791ea107cfae27421f12dce9b001a8ff1d60f38c972362fbd659c4e53f750b35a6192ff66b4869280510286c3d585073d0ae
data/bin/judges CHANGED
@@ -29,7 +29,7 @@ require 'factbase'
29
29
  Encoding.default_external = Encoding::UTF_8
30
30
  Encoding.default_internal = Encoding::UTF_8
31
31
 
32
- ver = '0.0.17'
32
+ ver = '0.0.18'
33
33
 
34
34
  include GLI::App
35
35
 
@@ -58,6 +58,8 @@ desc 'Update the factbase by passing all judges one by one'
58
58
  command :update do |c|
59
59
  c.desc 'Options to pass to every judge'
60
60
  c.flag([:o, :option], multiple: true, arg_name: '<key=value>')
61
+ c.desc 'Maximum number of update cycles to run'
62
+ c.flag([:'max-cycles'], default_value: 8)
61
63
  c.action do |global, options, args|
62
64
  require_relative '../lib/judges/commands/update'
63
65
  Judges::Update.new(loog).run(options, args)
data/features/cli.feature CHANGED
@@ -19,7 +19,7 @@ Feature: Simple Run
19
19
  n.kind = 'yes!'
20
20
  end
21
21
  """
22
- Then I run bin/judges with "--verbose update -o foo=1 -o bar=2 . simple.fb"
22
+ Then I run bin/judges with "--verbose update -o foo=1 -o bar=2 --max-cycles 2 . simple.fb"
23
23
  Then Stdout contains "foo → "
24
24
  Then Stdout contains "bar → "
25
25
  Then Stdout contains "1 judges processed"
@@ -44,17 +44,19 @@ Feature: Simple Run
44
44
  Given I make a temp directory
45
45
  Then I have a "simple/simple_judge.rb" file with content:
46
46
  """
47
+ return if $fb.size > 2
47
48
  $fb.insert.time = Time.now - 100 * 60 * 60 * 24
48
49
  """
49
50
  Then I run bin/judges with "--verbose update . simple.fb"
50
51
  Given I run bin/judges with "trim --days 5 simple.fb"
51
- Then Stdout contains "1 facts deleted"
52
+ Then Stdout contains "3 facts deleted"
52
53
  And Exit code is zero
53
54
 
54
55
  Scenario: Simple print of a small factbase
55
56
  Given I make a temp directory
56
57
  Then I have a "simple/simple_judge.rb" file with content:
57
58
  """
59
+ return if $fb.size > 2
58
60
  n = $fb.insert
59
61
  n.kind = 'yes!'
60
62
  """
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.17'
29
+ s.version = '0.0.18'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description = '
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.rdoc_options = ['--charset=UTF-8']
43
43
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
44
  s.add_runtime_dependency 'backtrace', '~> 0.3'
45
- s.add_runtime_dependency 'factbase', '~>0.0.15'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.16'
46
46
  s.add_runtime_dependency 'gli', '~>2.21'
47
47
  s.add_runtime_dependency 'loog', '~>0.2'
48
48
  s.add_runtime_dependency 'nokogiri', '~> 1.10'
@@ -44,8 +44,27 @@ class Judges::Update
44
44
  fb = impex.import(strict: false)
45
45
  options = Judges::Options.new(opts['option'])
46
46
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
47
+ packs = Judges::Packs.new(dir, @loog)
48
+ c = 0
49
+ loop do
50
+ diff = cycle(packs, fb, impex, options)
51
+ break if diff.zero?
52
+ if !opts['max-cycles'].nil? && c > opts['max-cycles']
53
+ @loog.info('Too many cycles already, as set by --max-cycles, breaking')
54
+ break
55
+ end
56
+ c += 1
57
+ @loog.info("#{diff} modifications at the cycle ##{c}")
58
+ end
59
+ @loog.info("Update finished in #{c} cycles")
60
+ end
61
+
62
+ private
63
+
64
+ def cycle(packs, fb, impex, options)
47
65
  errors = []
48
- done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
66
+ diff = 0
67
+ done = packs.each_with_index do |p, i|
49
68
  @loog.info("Running #{p.dir.to_rel} (##{i})...")
50
69
  before = fb.size
51
70
  begin
@@ -56,9 +75,11 @@ class Judges::Update
56
75
  end
57
76
  after = fb.size
58
77
  @loog.info("Pack #{p.dir.to_rel} added #{after - before} facts") if after > before
78
+ diff += after - before
59
79
  end
60
80
  @loog.info("#{done} judges processed (#{errors.size} errors)")
61
81
  raise "Failed to update correctly (#{errors.size} errors)" unless errors.empty?
62
82
  impex.export(fb)
83
+ diff
63
84
  end
64
85
  end
@@ -33,7 +33,7 @@ require_relative '../../lib/judges/commands/update'
33
33
  class TestUpdate < Minitest::Test
34
34
  def test_build_factbase_from_scratch
35
35
  Dir.mktmpdir do |d|
36
- File.write(File.join(d, 'foo.rb'), '$fb.insert.zzz = $options.foo_bar + 1')
36
+ File.write(File.join(d, 'foo.rb'), 'return if $fb.size > 2; $fb.insert.zzz = $options.foo_bar + 1')
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
@@ -49,7 +49,7 @@ class TestUpdate < Minitest::Test
49
49
  fb = Factbase.new
50
50
  fb.insert.foo_bar = 42
51
51
  File.binwrite(file, fb.export)
52
- File.write(File.join(d, 'foo.rb'), '$fb.insert.tt = 4')
52
+ File.write(File.join(d, 'foo.rb'), 'return if $fb.size > 2; $fb.insert.tt = 4')
53
53
  Judges::Update.new(Loog::VERBOSE).run({}, [d, file])
54
54
  fb = Factbase.new
55
55
  fb.import(File.binread(file))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-14 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.15
33
+ version: 0.0.16
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: 0.0.15
40
+ version: 0.0.16
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement