judges 0.0.27 → 0.0.28

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a113f833da56404725368db4e2fdb6047211835ef00e2cb4e5638f3f375be458
4
- data.tar.gz: 1cc2c79bcb113aad1b53ebd1743426069e8ce536c85ba489435a9ffb2a16232a
3
+ metadata.gz: b3d395cb5c5d1116843533c8a8d8576e346c8426ef1da8524d11c2fb00a65430
4
+ data.tar.gz: 648cb80dae16df946aec75075d3458b4fafaf04531e2cf2fe8bfa225353b4e3f
5
5
  SHA512:
6
- metadata.gz: 130c87d81f8b9d2e2c46c95bce66918c58732e15f4fba363ae0a85ad20448204275dff7bcbc1b0810304ba7e72f434ccab07dd523f1d31866c37c61c4cd6bf33
7
- data.tar.gz: b2cdb4ba68c86a471b561598d677919e75fc5f639e1a23a57665ed49d06e9ae7f8cba9a3a763f8c8bc5b94a3a256ba4c1798d898127c3448129be4fc096ab249
6
+ metadata.gz: 99f24ae2112c3e60ac802a82f7ba0f5b8c2f582fcbdf9fc8d92d89c2c8f52476c4566b67bd4996b06c0c3aa550573fc79ecfec534493a0a7f3c71fe9c247cc4d
7
+ data.tar.gz: 53d1db75b34ae7d2536bd9ef5787d5fa52d5cd16debb199702c15381a8d20de0a8a06359b3482b2ba9d48990cc4ceba4d73d93f8a9b6969b22dc7122b0c18ef3
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.27)
6
+ factbase (~> 0.0.28)
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.27)
77
+ factbase (0.0.28)
78
78
  json (~> 2.7)
79
79
  loog (~> 0.2)
80
80
  nokogiri (~> 1.10)
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.27'
35
+ ver = '0.0.28'
36
36
 
37
37
  loog = Loog::REGULAR
38
38
 
@@ -12,7 +12,7 @@ Feature: Update
12
12
  Then Stdout contains "foo → "
13
13
  Then Stdout contains "bar → "
14
14
  Then Stdout contains "1 judge(s) processed"
15
- Then Stdout contains "Update finished in 3 cycles"
15
+ Then Stdout contains "Update finished: 3 cycles"
16
16
  And Exit code is zero
17
17
 
18
18
  Scenario: Simple run of a few judges, with a lib
@@ -28,5 +28,5 @@ Feature: Update
28
28
  """
29
29
  Then I run bin/judges with "update --lib mylib --max-cycles 1 mypacks simple.fb"
30
30
  Then Stdout contains "1 judge(s) processed"
31
- Then Stdout contains "Update finished in 1 cycles"
31
+ Then Stdout contains "Update finished: 1 cycles"
32
32
  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.27'
29
+ s.version = '0.0.28'
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.27'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.28'
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'
@@ -0,0 +1,54 @@
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
+ require 'time'
24
+ require_relative '../../judges'
25
+ require_relative '../../judges/impex'
26
+ require_relative '../../judges/to_rel'
27
+
28
+ # Import.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class Judges::Import
33
+ def initialize(loog)
34
+ @loog = loog
35
+ end
36
+
37
+ def run(_opts, args)
38
+ raise 'Exactly two arguments required' unless args.size == 2
39
+ raise "File not found #{args[0].to_rel}" unless File.exist?(args[0])
40
+ start = Time.now
41
+ yaml = YAML.load_file(args[0], permitted_classes: [Time])
42
+ impex = Judges::Impex.new(@loog, args[1])
43
+ fb = impex.import(strict: false)
44
+ fb = Factbase::Looged.new(fb, @loog)
45
+ yaml.each do |i|
46
+ f = fb.insert
47
+ i.each do |p, v|
48
+ f.send("#{p}=", v)
49
+ end
50
+ end
51
+ impex.export(fb)
52
+ @loog.info("Import finished in #{format('%.02f', Time.now - start)}s")
53
+ end
54
+ end
@@ -46,6 +46,7 @@ class Judges::Test
46
46
  errors = []
47
47
  done = 0
48
48
  global = {}
49
+ start = Time.now
49
50
  Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
50
51
  local = {}
51
52
  next unless include?(opts, p.name)
@@ -62,13 +63,14 @@ class Judges::Test
62
63
  end
63
64
  done += 1
64
65
  end
66
+ lapse = "in #{format('%.02f', Time.now - start)}s"
65
67
  if done.zero?
66
68
  raise 'No judges tested :(' unless opts['quiet']
67
- @loog.warn("\n👍 No judges tested")
69
+ @loog.warn("\n👍 No judges tested #{lapse}")
68
70
  elsif errors.empty?
69
- @loog.info("\n👍 All #{done} judge(s) tested successfully")
71
+ @loog.info("\n👍 All #{done} judge(s) tested successfully #{lapse}")
70
72
  else
71
- @loog.info("\n❌ #{done} judge(s) tested, #{errors.size} of them failed")
73
+ @loog.info("\n❌ #{done} judge(s) tested, #{errors.size} of them failed #{lapse}")
72
74
  raise "#{errors.size} tests failed" unless opts['quiet']
73
75
  end
74
76
  end
@@ -46,11 +46,13 @@ class Judges::Trim
46
46
  else
47
47
  raise 'Specify either --days or --query' unless opts['days'].nil?
48
48
  end
49
+ start = Time.now
49
50
  deleted = fb.query(query).delete!
51
+ lapse = "in #{format('%.02f', Time.now - start)}s"
50
52
  if deleted.zero?
51
- @loog.info('No facts deleted')
53
+ @loog.info("No facts deleted #{lapse}")
52
54
  else
53
- @loog.info("🗑 #{deleted} fact(s) deleted")
55
+ @loog.info("🗑 #{deleted} fact(s) deleted #{lapse}")
54
56
  impex.export(fb)
55
57
  end
56
58
  end
@@ -48,6 +48,7 @@ class Judges::Update
48
48
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
49
49
  packs = Judges::Packs.new(dir, opts['lib'], @loog)
50
50
  c = 0
51
+ start = Time.now
51
52
  loop do
52
53
  c += 1
53
54
  diff = cycle(opts, packs, fb, options)
@@ -57,11 +58,13 @@ class Judges::Update
57
58
  @loog.info('Too many cycles already, as set by --max-cycles, breaking')
58
59
  break
59
60
  end
60
- @loog.info("By #{diff} facts the factbase \
61
- #{diff.positive? ? 'increased' : 'decreased'} \
62
- its size at the cycle ##{c}")
61
+ @loog.info(
62
+ "By #{diff} facts the factbase " \
63
+ "#{diff.positive? ? 'increased' : 'decreased'} " \
64
+ "its size at the cycle ##{c}"
65
+ )
63
66
  end
64
- @loog.info("Update finished in #{c} cycles")
67
+ @loog.info("Update finished: #{c} cycles in #{format('%.02f', Time.now - start)}s")
65
68
  end
66
69
 
67
70
  private
@@ -35,7 +35,7 @@ class TestEval < Minitest::Test
35
35
  def test_build_factbase_from_scratch
36
36
  Dir.mktmpdir do |d|
37
37
  file = File.join(d, 'base.fb')
38
- Judges::Eval.new(Loog::VERBOSE).run({}, [file, '$fb.insert.foo = 42'])
38
+ Judges::Eval.new(Loog::NULL).run({}, [file, '$fb.insert.foo = 42'])
39
39
  fb = Factbase.new
40
40
  fb.import(File.binread(file))
41
41
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
@@ -0,0 +1,57 @@
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
+ require 'minitest/autorun'
24
+ require 'loog'
25
+ require 'nokogiri'
26
+ require 'factbase/to_xml'
27
+ require_relative '../../lib/judges'
28
+ require_relative '../../lib/judges/commands/import'
29
+
30
+ # Test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # License:: MIT
34
+ class TestImport < Minitest::Test
35
+ def test_import_from_yaml
36
+ Dir.mktmpdir do |d|
37
+ file = File.join(d, 'base.fb')
38
+ yaml = File.join(d, 'input.yml')
39
+ File.write(
40
+ yaml,
41
+ <<-YAML
42
+ -
43
+ foo: 42
44
+ bar: 2024-03-04T22:22:22Z
45
+ t: Hello, world!
46
+ -
47
+ z: 3.14
48
+ YAML
49
+ )
50
+ Judges::Import.new(Loog::NULL).run({}, [yaml, file])
51
+ fb = Factbase.new
52
+ fb.import(File.binread(file))
53
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
54
+ assert(!xml.xpath('/fb[count(f)=2]').empty?, xml)
55
+ end
56
+ end
57
+ end
@@ -42,7 +42,7 @@ class TestJoin < Minitest::Test
42
42
  fb2 = Factbase.new
43
43
  fb2.insert.foo_bar = 42
44
44
  File.binwrite(slave, fb2.export)
45
- Judges::Join.new(Loog::VERBOSE).run({}, [master, slave])
45
+ Judges::Join.new(Loog::NULL).run({}, [master, slave])
46
46
  fb = Factbase.new
47
47
  fb.import(File.binread(master))
48
48
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
@@ -38,7 +38,7 @@ class TestPrint < Minitest::Test
38
38
  fb = Factbase.new
39
39
  fb.insert
40
40
  File.binwrite(f, fb.export)
41
- Judges::Print.new(Loog::VERBOSE).run({ format: 'yaml', auto: true }, [f])
41
+ Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
42
42
  y = File.join(d, 'base.yaml')
43
43
  assert(File.exist?(y))
44
44
  assert_equal(1, YAML.load_file(y)['facts'].size)
@@ -39,7 +39,7 @@ class TestTrim < Minitest::Test
39
39
  before.insert.time = Time.now + 1
40
40
  before.insert.time = Time.now - (100 * 24 * 60 * 60)
41
41
  File.binwrite(file, before.export)
42
- Judges::Trim.new(Loog::VERBOSE).run({ 'days' => 10 }, [file])
42
+ Judges::Trim.new(Loog::NULL).run({ 'days' => 10 }, [file])
43
43
  after = Factbase.new
44
44
  after.import(File.binread(file))
45
45
  assert_equal(1, after.size)
@@ -36,7 +36,7 @@ class TestUpdate < Minitest::Test
36
36
  Dir.mktmpdir do |d|
37
37
  File.write(File.join(d, 'foo.rb'), 'return if $fb.size > 2; $fb.insert.zzz = $options.foo_bar + 1')
38
38
  file = File.join(d, 'base.fb')
39
- Judges::Update.new(Loog::VERBOSE).run({ 'option' => ['foo_bar=42'] }, [d, file])
39
+ Judges::Update.new(Loog::NULL).run({ 'option' => ['foo_bar=42'] }, [d, file])
40
40
  fb = Factbase.new
41
41
  fb.import(File.binread(file))
42
42
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
@@ -51,7 +51,7 @@ class TestUpdate < Minitest::Test
51
51
  fb.insert.foo_bar = 42
52
52
  File.binwrite(file, fb.export)
53
53
  File.write(File.join(d, 'foo.rb'), '$fb.insert.tt = 4')
54
- Judges::Update.new(Loog::VERBOSE).run({ 'max-cycles' => 1 }, [d, file])
54
+ Judges::Update.new(Loog::NULL).run({ 'max-cycles' => 1 }, [d, file])
55
55
  fb = Factbase.new
56
56
  fb.import(File.binread(file))
57
57
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
@@ -64,7 +64,7 @@ class TestUpdate < Minitest::Test
64
64
  Dir.mktmpdir do |d|
65
65
  File.write(File.join(d, 'foo.rb'), 'this is a broken Ruby script')
66
66
  file = File.join(d, 'base.fb')
67
- Judges::Update.new(Loog::VERBOSE).run({ 'quiet' => true }, [d, file])
67
+ Judges::Update.new(Loog::NULL).run({ 'quiet' => true }, [d, file])
68
68
  end
69
69
  end
70
70
  end
@@ -80,13 +80,13 @@ class TestIfAbsent < Minitest::Test
80
80
  def test_complex_injects
81
81
  fb = Factbase.new
82
82
  f1 = fb.insert
83
- f1.foo = 'hello, "dude"!'
83
+ f1.foo = 'hello, dude!'
84
84
  f1.abc = 42
85
85
  t = Time.now
86
86
  f1.z = t
87
87
  f1.bar = 3.14
88
88
  n = if_absent(fb) do |f|
89
- f.foo = 'hello, "dude"!'
89
+ f.foo = "hello, \\\"dude\\\" \\' \\' ( \n\n ) (!"
90
90
  f.abc = 42
91
91
  f.z = t + 1
92
92
  f.bar = 3.15
data/test/test_impex.rb CHANGED
@@ -34,7 +34,7 @@ class TestImpex < Minitest::Test
34
34
  def test_basic
35
35
  Dir.mktmpdir do |d|
36
36
  f = File.join(d, 'foo.rb')
37
- impex = Judges::Impex.new(Loog::VERBOSE, f)
37
+ impex = Judges::Impex.new(Loog::NULL, f)
38
38
  impex.import(strict: false)
39
39
  impex.export(Factbase.new)
40
40
  end
@@ -43,7 +43,7 @@ class TestImpex < Minitest::Test
43
43
  def test_strict_import
44
44
  Dir.mktmpdir do |d|
45
45
  f = File.join(d, 'x.rb')
46
- impex = Judges::Impex.new(Loog::VERBOSE, f)
46
+ impex = Judges::Impex.new(Loog::NULL, f)
47
47
  impex.import(strict: false)
48
48
  impex.export(Factbase.new)
49
49
  impex.import
data/test/test_pack.rb CHANGED
@@ -35,7 +35,7 @@ class TestPack < Minitest::Test
35
35
  def test_basic_run
36
36
  Dir.mktmpdir do |d|
37
37
  File.write(File.join(d, 'foo.rb'), '$fb.insert')
38
- pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
38
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
39
39
  fb = Factbase.new
40
40
  pack.run(fb, {}, {}, {})
41
41
  assert_equal(1, fb.size)
@@ -45,7 +45,7 @@ class TestPack < Minitest::Test
45
45
  def test_run_isolated
46
46
  Dir.mktmpdir do |d|
47
47
  File.write(File.join(d, 'bar.rb'), '$fb.insert')
48
- pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
48
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
49
49
  fb1 = Factbase.new
50
50
  pack.run(fb1, {}, {}, {})
51
51
  assert_equal(1, fb1.size)
@@ -58,7 +58,7 @@ class TestPack < Minitest::Test
58
58
  def test_with_supplemenary_functions
59
59
  Dir.mktmpdir do |d|
60
60
  File.write(File.join(d, 'x.rb'), 'once($fb).insert')
61
- pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
61
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
62
62
  pack.run(Factbase.new, {}, {}, {})
63
63
  end
64
64
  end
@@ -101,7 +101,7 @@ class TestPack < Minitest::Test
101
101
  lib = File.join(d, 'lib')
102
102
  FileUtils.mkdir_p(lib)
103
103
  File.write(File.join(lib, 'y.rb'), '$foo = 42')
104
- pack = Judges::Pack.new(dir, lib, Loog::VERBOSE)
104
+ pack = Judges::Pack.new(dir, lib, Loog::NULL)
105
105
  fb = Factbase.new
106
106
  pack.run(fb, {}, {}, {})
107
107
  assert_equal(42, fb.query('()').each.to_a.first.bar)
data/test/test_packs.rb CHANGED
@@ -36,7 +36,7 @@ class TestPacks < Minitest::Test
36
36
  File.write(File.join(d, 'foo.rb'), 'hey')
37
37
  File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
38
38
  found = 0
39
- Judges::Packs.new(d, nil, Loog::VERBOSE).each do |p|
39
+ Judges::Packs.new(d, nil, Loog::NULL).each do |p|
40
40
  assert_equal('foo.rb', p.script)
41
41
  found += 1
42
42
  assert_equal('something.yml', File.basename(p.tests.first))
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.27
4
+ version: 0.0.28
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.27
33
+ version: 0.0.28
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.27
40
+ version: 0.0.28
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +129,7 @@ files:
129
129
  - judges.gemspec
130
130
  - lib/judges.rb
131
131
  - lib/judges/commands/eval.rb
132
+ - lib/judges/commands/import.rb
132
133
  - lib/judges/commands/inspect.rb
133
134
  - lib/judges/commands/join.rb
134
135
  - lib/judges/commands/print.rb
@@ -144,6 +145,7 @@ files:
144
145
  - lib/judges/to_rel.rb
145
146
  - renovate.json
146
147
  - test/commands/test_eval.rb
148
+ - test/commands/test_import.rb
147
149
  - test/commands/test_inspect.rb
148
150
  - test/commands/test_join.rb
149
151
  - test/commands/test_print.rb