judges 0.0.30 → 0.0.31

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: 2966161948e1ac2ed8c36b5f0e515183a9f8ea02d6ddabf396e7bd5db98ca787
4
- data.tar.gz: 227712553b74473211e835d5c1df9afbf03e00d8942639d137fea6d98d40a236
3
+ metadata.gz: 1c9e50999193ddf009d02379799add455856fae20b4f47e67a1760d56d7de3b0
4
+ data.tar.gz: af70fa8273042c07df059589181795769518c94d54c4430cf9fe9d2999da799a
5
5
  SHA512:
6
- metadata.gz: 120d2cec10fbca12aa6a9107ea348236dd44e999a8499dbef93952cb2fb313ea11bb67c658d0ebb6b6ee4f002383d2f8177d75d06bd8cb01d547032222e6b9aa
7
- data.tar.gz: 3cf907ef01704e0e11ffa8313226420536436571ab11ea9a25cf4d8c7cbc98e334cbb7e193ea5994910c36c20dcf29d0ae1d1fee040cefca9c7b5d2c0ec91a33
6
+ metadata.gz: ce9ee17c4b5cf1aadc125678bde1e0a7b4bd07a6e1cb2e54696e5e478a68371f9e4c7a6c18f7961be77f056903a1e49eb943d4c9d949fedb96db71ed2f23350e
7
+ data.tar.gz: fbadf8ca9127b21114b483b7a7f5e6b109d8c804f101a27fe6140c6a77e68a0f522bda5b32a366415b946d1c59c01130ab509a22e9f5c95037dbf605414d7667
data/Gemfile.lock CHANGED
@@ -3,7 +3,7 @@ PATH
3
3
  specs:
4
4
  judges (0.0.0)
5
5
  backtrace (~> 0.3)
6
- factbase (~> 0.0.29)
6
+ factbase (~> 0.0.30)
7
7
  gli (~> 2.21)
8
8
  loog (~> 0.2)
9
9
  nokogiri (~> 1.10)
@@ -74,7 +74,7 @@ GEM
74
74
  docile (1.4.0)
75
75
  drb (2.2.1)
76
76
  erubi (1.12.0)
77
- factbase (0.0.29)
77
+ factbase (0.0.30)
78
78
  json (~> 2.7)
79
79
  loog (~> 0.2)
80
80
  nokogiri (~> 1.10)
@@ -112,7 +112,7 @@ GEM
112
112
  racc
113
113
  psych (5.1.2)
114
114
  stringio
115
- racc (1.7.3)
115
+ racc (1.8.0)
116
116
  rack (3.0.11)
117
117
  rack-session (2.0.0)
118
118
  rack (>= 3.0.0)
data/bin/judges CHANGED
@@ -32,7 +32,7 @@ Encoding.default_internal = Encoding::UTF_8
32
32
  class App
33
33
  extend GLI::App
34
34
 
35
- ver = '0.0.30'
35
+ ver = '0.0.31'
36
36
 
37
37
  loog = Loog::REGULAR
38
38
 
@@ -13,5 +13,5 @@ Feature: Import
13
13
  z: 3.14
14
14
  """
15
15
  Then I run bin/judges with "--verbose import simple.yaml simple.fb"
16
- Then Stdout contains "Import finished"
16
+ Then Stdout contains "Import of 2 facts finished"
17
17
  And Exit code is zero
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.30'
29
+ s.version = '0.0.31'
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.29'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.30'
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'
@@ -20,13 +20,10 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require 'backtrace'
24
23
  require 'factbase/looged'
25
24
  require_relative '../../judges'
26
- require_relative '../../judges/to_rel'
27
- require_relative '../../judges/packs'
28
- require_relative '../../judges/options'
29
25
  require_relative '../../judges/impex'
26
+ require_relative '../../judges/elapsed'
30
27
 
31
28
  # Eval.
32
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -40,12 +37,15 @@ class Judges::Eval
40
37
  def run(_opts, args)
41
38
  raise 'Exactly two arguments required' unless args.size == 2
42
39
  impex = Judges::Impex.new(@loog, args[0])
43
- $fb = impex.import(strict: false)
44
- $fb = Factbase::Looged.new($fb, @loog)
45
- expr = args[1]
46
- # rubocop:disable Security/Eval
47
- eval(expr)
48
- # rubocop:enable Security/Eval
49
- impex.export($fb)
40
+ elapsed(@loog) do
41
+ $fb = impex.import(strict: false)
42
+ $fb = Factbase::Looged.new($fb, @loog)
43
+ expr = args[1]
44
+ # rubocop:disable Security/Eval
45
+ eval(expr)
46
+ # rubocop:enable Security/Eval
47
+ impex.export($fb)
48
+ throw :'Evaluated successfully'
49
+ end
50
50
  end
51
51
  end
@@ -25,6 +25,7 @@ require 'factbase/looged'
25
25
  require_relative '../../judges'
26
26
  require_relative '../../judges/impex'
27
27
  require_relative '../../judges/to_rel'
28
+ require_relative '../../judges/elapsed'
28
29
 
29
30
  # Import.
30
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -38,19 +39,20 @@ class Judges::Import
38
39
  def run(_opts, args)
39
40
  raise 'Exactly two arguments required' unless args.size == 2
40
41
  raise "File not found #{args[0].to_rel}" unless File.exist?(args[0])
41
- start = Time.now
42
- yaml = YAML.load_file(args[0], permitted_classes: [Time])
43
- @loog.info("YAML loaded from #{args[0].to_rel} (#{yaml.size} facts)")
44
- impex = Judges::Impex.new(@loog, args[1])
45
- fb = impex.import(strict: false)
46
- fb = Factbase::Looged.new(fb, @loog)
47
- yaml.each do |i|
48
- f = fb.insert
49
- i.each do |p, v|
50
- f.send("#{p}=", v)
42
+ elapsed(@loog) do
43
+ yaml = YAML.load_file(args[0], permitted_classes: [Time])
44
+ @loog.info("YAML loaded from #{args[0].to_rel} (#{yaml.size} facts)")
45
+ impex = Judges::Impex.new(@loog, args[1])
46
+ fb = impex.import(strict: false)
47
+ fb = Factbase::Looged.new(fb, @loog)
48
+ yaml.each do |i|
49
+ f = fb.insert
50
+ i.each do |p, v|
51
+ f.send("#{p}=", v)
52
+ end
51
53
  end
54
+ impex.export(fb)
55
+ throw :"Import of #{yaml.size} facts finished"
52
56
  end
53
- impex.export(fb)
54
- @loog.info("Import finished in #{format('%.02f', Time.now - start)}s")
55
57
  end
56
58
  end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require_relative '../../judges'
24
24
  require_relative '../../judges/impex'
25
+ require_relative '../../judges/elapsed'
25
26
 
26
27
  # Join.
27
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -36,9 +37,11 @@ class Judges::Join
36
37
  raise 'Exactly two arguments required' unless args.size == 2
37
38
  master = Judges::Impex.new(@loog, args[0])
38
39
  slave = Judges::Impex.new(@loog, args[1])
39
- fb = master.import
40
- slave.import_to(fb)
41
- master.export(fb)
42
- @loog.info('Two factbases joined')
40
+ elapsed(@loog) do
41
+ fb = master.import
42
+ slave.import_to(fb)
43
+ master.export(fb)
44
+ throw :'Two factbases joined'
45
+ end
43
46
  end
44
47
  end
@@ -24,6 +24,7 @@ require 'fileutils'
24
24
  require 'factbase'
25
25
  require_relative '../../judges'
26
26
  require_relative '../../judges/impex'
27
+ require_relative '../../judges/elapsed'
27
28
 
28
29
  # Update.
29
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -53,20 +54,21 @@ class Judges::Print
53
54
  end
54
55
  @loog.debug("The factbase #{f.to_rel} is younger than the target #{o.to_rel}, need to print")
55
56
  end
56
- start = Time.now
57
- output =
58
- case opts[:format].downcase
59
- when 'yaml'
60
- require 'factbase/to_yaml'
61
- Factbase::ToYAML.new(fb).yaml
62
- when 'json'
63
- require 'factbase/to_json'
64
- Factbase::ToJSON.new(fb).json
65
- when 'xml'
66
- require 'factbase/to_xml'
67
- Factbase::ToXML.new(fb).xml
68
- end
69
- File.binwrite(o, output)
70
- @loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes) in #{format('%.02f', Time.now - start)}s")
57
+ elapsed(@loog) do
58
+ output =
59
+ case opts[:format].downcase
60
+ when 'yaml'
61
+ require 'factbase/to_yaml'
62
+ Factbase::ToYAML.new(fb).yaml
63
+ when 'json'
64
+ require 'factbase/to_json'
65
+ Factbase::ToJSON.new(fb).json
66
+ when 'xml'
67
+ require 'factbase/to_xml'
68
+ Factbase::ToXML.new(fb).xml
69
+ end
70
+ File.binwrite(o, output)
71
+ throw :"Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)"
72
+ end
71
73
  end
72
74
  end
@@ -29,6 +29,7 @@ require_relative '../../judges'
29
29
  require_relative '../../judges/to_rel'
30
30
  require_relative '../../judges/packs'
31
31
  require_relative '../../judges/options'
32
+ require_relative '../../judges/elapsed'
32
33
 
33
34
  # Test.
34
35
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -46,33 +47,29 @@ class Judges::Test
46
47
  errors = []
47
48
  done = 0
48
49
  global = {}
49
- start = Time.now
50
- Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
51
- local = {}
52
- next unless include?(opts, p.name)
53
- @loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
54
- p.tests.each do |f|
55
- yaml = YAML.load_file(f, permitted_classes: [Time])
56
- @loog.info("Testing #{f.to_rel}:")
57
- begin
58
- test_one(p, global, local, yaml)
59
- rescue StandardError => e
60
- @loog.warn(Backtrace.new(e))
61
- errors << f
50
+ elapsed(@loog) do
51
+ Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
52
+ local = {}
53
+ next unless include?(opts, p.name)
54
+ @loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
55
+ p.tests.each do |f|
56
+ yaml = YAML.load_file(f, permitted_classes: [Time])
57
+ @loog.info("Testing #{f.to_rel}:")
58
+ begin
59
+ test_one(p, global, local, yaml)
60
+ rescue StandardError => e
61
+ @loog.warn(Backtrace.new(e))
62
+ errors << f
63
+ end
62
64
  end
65
+ done += 1
63
66
  end
64
- done += 1
65
- end
66
- lapse = "in #{format('%.02f', Time.now - start)}s"
67
- if done.zero?
68
- raise 'No judges tested :(' unless opts['quiet']
69
- @loog.warn("\n👍 No judges tested #{lapse}")
70
- elsif errors.empty?
71
- @loog.info("\n👍 All #{done} judge(s) tested successfully #{lapse}")
72
- else
73
- @loog.info("\n❌ #{done} judge(s) tested, #{errors.size} of them failed #{lapse}")
74
- raise "#{errors.size} tests failed" unless opts['quiet']
67
+ throw :'👍 No judges tested' if done.zero?
68
+ throw :"👍 All #{done} judge(s) tested successfully" if errors.empty?
69
+ throw :" #{done} judge(s) tested, #{errors.size} of them failed"
75
70
  end
71
+ raise "#{errors.size} tests failed" unless opts['quiet'] || errors.empty?
72
+ raise 'No judges tested :(' unless opts['quiet'] || !done.zero?
76
73
  end
77
74
 
78
75
  private
@@ -23,6 +23,7 @@
23
23
  require 'time'
24
24
  require_relative '../../judges'
25
25
  require_relative '../../judges/impex'
26
+ require_relative '../../judges/elapsed'
26
27
 
27
28
  # Trim.
28
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -46,14 +47,11 @@ class Judges::Trim
46
47
  else
47
48
  raise 'Specify either --days or --query' unless opts['days'].nil?
48
49
  end
49
- start = Time.now
50
- deleted = fb.query(query).delete!
51
- lapse = "in #{format('%.02f', Time.now - start)}s"
52
- if deleted.zero?
53
- @loog.info("No facts deleted #{lapse}")
54
- else
55
- @loog.info("🗑 #{deleted} fact(s) deleted #{lapse}")
50
+ elapsed(@loog) do
51
+ deleted = fb.query(query).delete!
52
+ throw :'No facts deleted' if deleted.zero?
56
53
  impex.export(fb)
54
+ throw :"🗑 #{deleted} fact(s) deleted"
57
55
  end
58
56
  end
59
57
  end
@@ -27,6 +27,7 @@ require_relative '../../judges/to_rel'
27
27
  require_relative '../../judges/packs'
28
28
  require_relative '../../judges/options'
29
29
  require_relative '../../judges/impex'
30
+ require_relative '../../judges/elapsed'
30
31
 
31
32
  # Update.
32
33
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -48,23 +49,27 @@ class Judges::Update
48
49
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
49
50
  packs = Judges::Packs.new(dir, opts['lib'], @loog)
50
51
  c = 0
51
- start = Time.now
52
- loop do
53
- c += 1
54
- diff = cycle(opts, packs, fb, options)
55
- impex.export(fb)
56
- break if diff.zero?
57
- if !opts['max-cycles'].nil? && c >= opts['max-cycles']
58
- @loog.info('Too many cycles already, as set by --max-cycles, breaking')
59
- break
52
+ elapsed(@loog) do
53
+ loop do
54
+ c += 1
55
+ if c > 1
56
+ @loog.info("\n\nStarting cycle ##{c}#{opts['max-cycles'] ? " (out of #{opts['max-cycles']})" : ''}...")
57
+ end
58
+ diff = cycle(opts, packs, fb, options)
59
+ impex.export(fb)
60
+ break if diff.zero?
61
+ if !opts['max-cycles'].nil? && c >= opts['max-cycles']
62
+ @loog.info('Too many cycles already, as set by --max-cycles, breaking')
63
+ break
64
+ end
65
+ @loog.info(
66
+ "By #{diff} facts the factbase " \
67
+ "#{diff.positive? ? 'increased' : 'decreased'} " \
68
+ "its size at the cycle ##{c}"
69
+ )
60
70
  end
61
- @loog.info(
62
- "By #{diff} facts the factbase " \
63
- "#{diff.positive? ? 'increased' : 'decreased'} " \
64
- "its size at the cycle ##{c}"
65
- )
71
+ throw :"Update finished: #{c} cycles"
66
72
  end
67
- @loog.info("Update finished: #{c} cycles in #{format('%.02f', Time.now - start)}s")
68
73
  end
69
74
 
70
75
  private
@@ -73,26 +78,25 @@ class Judges::Update
73
78
  errors = []
74
79
  diff = 0
75
80
  global = {}
76
- done = packs.each_with_index do |p, i|
77
- local = {}
78
- @loog.info("👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
79
- before = fb.size
80
- begin
81
- p.run(fb, global, local, options)
82
- rescue StandardError => e
83
- @loog.warn(Backtrace.new(e))
84
- errors << p.script
81
+ elapsed(@loog) do
82
+ done = packs.each_with_index do |p, i|
83
+ local = {}
84
+ @loog.info("👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
85
+ before = fb.size
86
+ begin
87
+ p.run(fb, global, local, options)
88
+ rescue StandardError => e
89
+ @loog.warn(Backtrace.new(e))
90
+ errors << p.script
91
+ end
92
+ after = fb.size
93
+ @loog.info("👍 The judge #{p.dir.to_rel} added #{after - before} facts") if after > before
94
+ diff += after - before
85
95
  end
86
- after = fb.size
87
- @loog.info("👍 Pack #{p.dir.to_rel} added #{after - before} facts") if after > before
88
- diff += after - before
89
- end
90
- if errors.empty?
91
- @loog.info("👍 #{done} judge(s) processed")
92
- else
93
- @loog.info("❌ #{done} judge(s) processed with #{errors.size} errors")
94
- raise "Failed to update correctly (#{errors.size} errors)" unless opts['quiet']
96
+ throw :"👍 #{done} judge(s) processed" if errors.empty?
97
+ throw :" #{done} judge(s) processed with #{errors.size} errors"
95
98
  end
99
+ raise "Failed to update correctly (#{errors.size} errors)" unless errors.empty? || opts['quiet']
96
100
  diff
97
101
  end
98
102
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ def elapsed(loog)
24
+ start = Time.now
25
+ begin
26
+ yield
27
+ rescue UncaughtThrowError => e
28
+ tag = e.tag
29
+ throw e unless tag.is_a?(Symbol)
30
+ loog.info("#{tag} in #{format('%.02f', Time.now - start)}s")
31
+ end
32
+ end
data/lib/judges/pack.rb CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  require_relative '../judges'
24
24
  require_relative '../judges/to_rel'
25
+ require_relative '../judges/elapsed'
25
26
  require_relative '../judges/fb/once'
26
27
  require_relative '../judges/fb/if_absent'
27
28
 
@@ -55,8 +56,9 @@ class Judges::Pack
55
56
  end
56
57
  s = File.join(@dir, script)
57
58
  raise "Can't load '#{s}'" unless File.exist?(s)
58
- begin
59
+ elapsed(@loog) do
59
60
  load(s, true)
61
+ throw :"#{name} finished"
60
62
  ensure
61
63
  $fb = $judge = $options = $loog = nil
62
64
  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.30
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.29
33
+ version: 0.0.30
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.29
40
+ version: 0.0.30
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +137,7 @@ files:
137
137
  - lib/judges/commands/test.rb
138
138
  - lib/judges/commands/trim.rb
139
139
  - lib/judges/commands/update.rb
140
+ - lib/judges/elapsed.rb
140
141
  - lib/judges/fb/if_absent.rb
141
142
  - lib/judges/fb/once.rb
142
143
  - lib/judges/impex.rb