judges 0.0.26 → 0.0.27

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: 0a2c905f28928721f9ed99956f7e9eea5e3b4eabf21a7bffdc324651ea2bf213
4
- data.tar.gz: 4e6cb24b4b4aff6b8bab408d5038a8fee454382d293972ddcf78bab0d2c37b51
3
+ metadata.gz: a113f833da56404725368db4e2fdb6047211835ef00e2cb4e5638f3f375be458
4
+ data.tar.gz: 1cc2c79bcb113aad1b53ebd1743426069e8ce536c85ba489435a9ffb2a16232a
5
5
  SHA512:
6
- metadata.gz: ad604005840c419cc0021cc0d55a64c010ca6ab64c73f5e30cfa72c9e43190382b5bf6783794389eb3f21cc6fd24d3b60c3c3f803f29f71480a0eb73cfa7995f
7
- data.tar.gz: 4888625231190957df7b5c189215b49cb9ed1ec01c40edf795140a4d6896d7a9b6d7d24e4dd02bf931281ee25ec2db87590be3275d97aa2980cfd3eb7b44a1cf
6
+ metadata.gz: 130c87d81f8b9d2e2c46c95bce66918c58732e15f4fba363ae0a85ad20448204275dff7bcbc1b0810304ba7e72f434ccab07dd523f1d31866c37c61c4cd6bf33
7
+ data.tar.gz: b2cdb4ba68c86a471b561598d677919e75fc5f639e1a23a57665ed49d06e9ae7f8cba9a3a763f8c8bc5b94a3a256ba4c1798d898127c3448129be4fc096ab249
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.23)
6
+ factbase (~> 0.0.27)
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.23)
77
+ factbase (0.0.27)
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.26'
35
+ ver = '0.0.27'
36
36
 
37
37
  loog = Loog::REGULAR
38
38
 
@@ -71,8 +71,16 @@ class App
71
71
  end
72
72
  end
73
73
 
74
+ desc 'Evaluate a single Ruby expression on the factbase'
75
+ command :eval do |c|
76
+ c.action do |global, options, args|
77
+ require_relative '../lib/judges/commands/eval'
78
+ Judges::Eval.new(loog).run(options, args)
79
+ end
80
+ end
81
+
74
82
  desc 'Join two factbases'
75
- command :print do |c|
83
+ command :join do |c|
76
84
  c.action do |global, options, args|
77
85
  require_relative '../lib/judges/commands/join'
78
86
  Judges::Join.new(loog).run(options, args)
@@ -81,8 +89,10 @@ class App
81
89
 
82
90
  desc 'Remove the facts that are too old'
83
91
  command :trim do |c|
92
+ c.desc 'Only the facts that match the expression are deleted'
93
+ c.flag([:query])
84
94
  c.desc 'Remove facts that are older than X days'
85
- c.flag([:days], type: Integer, default_value: 90)
95
+ c.flag([:days], type: Integer)
86
96
  c.action do |global, options, args|
87
97
  require_relative '../lib/judges/commands/trim'
88
98
  Judges::Trim.new(loog).run(options, args)
@@ -95,6 +105,8 @@ class App
95
105
  c.flag([:format], default_value: 'yaml')
96
106
  c.desc 'Generate output name of the file automatically'
97
107
  c.switch([:auto], default_value: false)
108
+ c.desc 'Only the facts that match the expression are printed'
109
+ c.flag([:query], default_value: '()')
98
110
  c.action do |global, options, args|
99
111
  require_relative '../lib/judges/commands/print'
100
112
  Judges::Print.new(loog).run(options, args)
@@ -3,14 +3,9 @@ Feature: Inspect
3
3
 
4
4
  Scenario: Simple inspect of a small factbase
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
7
- """
8
- return if $fb.size > 2
9
- n = $fb.insert
10
- n.kind = 'yes!'
11
- """
6
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
12
7
  Then I run bin/judges with "update . simple.fb"
13
8
  Then I run bin/judges with "inspect simple.fb"
14
- Then Stdout contains "Facts: 3"
9
+ Then Stdout contains "Facts: 1"
15
10
  And Exit code is zero
16
11
 
@@ -0,0 +1,12 @@
1
+ Feature: Join
2
+ I want to join two factbases
3
+
4
+ Scenario: Simple join of two small factbases
5
+ Given I make a temp directory
6
+ Then I run bin/judges with "--verbose eval first.fb '$fb.insert.foo = 42'"
7
+ Then I run bin/judges with "--verbose eval second.fb '$fb.insert.foo = 42'"
8
+ Then I run bin/judges with "update . first.fb"
9
+ Then I run bin/judges with "update . second.fb"
10
+ Then I run bin/judges with "join first.fb second.fb"
11
+ Then Stdout contains "joined"
12
+ And Exit code is zero
@@ -3,12 +3,7 @@ Feature: Print
3
3
 
4
4
  Scenario: Simple print of a small factbase, to YAML
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
7
- """
8
- return if $fb.size > 2
9
- n = $fb.insert
10
- n.kind = 'yes!'
11
- """
6
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
12
7
  Then I run bin/judges with "update . simple.fb"
13
8
  Then I run bin/judges with "print --format=yaml simple.fb simple.yml"
14
9
  Then Stdout contains "printed"
@@ -16,12 +11,7 @@ Feature: Print
16
11
 
17
12
  Scenario: Simple print of a small factbase, to JSON
18
13
  Given I make a temp directory
19
- Then I have a "simple/simple_judge.rb" file with content:
20
- """
21
- return if $fb.size > 2
22
- n = $fb.insert
23
- n.kind = 'yes!'
24
- """
14
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
25
15
  Then I run bin/judges with "update . simple.fb"
26
16
  Then I run bin/judges with "print --format=json simple.fb simple.json"
27
17
  Then Stdout contains "printed"
@@ -29,13 +19,17 @@ Feature: Print
29
19
 
30
20
  Scenario: Simple print of a small factbase, to XML
31
21
  Given I make a temp directory
32
- Then I have a "simple/simple_judge.rb" file with content:
33
- """
34
- return if $fb.size > 2
35
- n = $fb.insert
36
- n.kind = 'yes!'
37
- """
22
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
38
23
  Then I run bin/judges with "update . simple.fb"
39
24
  Then I run bin/judges with "print --format=xml --auto simple.fb"
40
25
  Then Stdout contains "printed"
41
26
  And Exit code is zero
27
+
28
+ Scenario: Simple print of a small factbase, to XML, with a query
29
+ Given I make a temp directory
30
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
31
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 43'"
32
+ Then I run bin/judges with "update . simple.fb"
33
+ Then I run bin/judges with "print '--query=(eq foo 43)' --auto simple.fb"
34
+ Then Stdout contains "printed"
35
+ And Exit code is zero
@@ -3,12 +3,15 @@ Feature: Trim
3
3
 
4
4
  Scenario: Simple trimming of a factbase
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
7
- """
8
- return if $fb.size > 2
9
- $fb.insert.time = Time.now - 100 * 60 * 60 * 24
10
- """
6
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.time = Time.now - 100 * 60 * 60 * 24'"
11
7
  Then I run bin/judges with "--verbose update . simple.fb"
12
8
  Given I run bin/judges with "trim --days 5 simple.fb"
13
- Then Stdout contains "3 fact(s) deleted"
9
+ Then Stdout contains "1 fact(s) deleted"
10
+ And Exit code is zero
11
+
12
+ Scenario: Simple trimming of a factbase, with a query
13
+ Given I make a temp directory
14
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
15
+ Given I run bin/judges with "trim --query '(eq foo 42)' simple.fb"
16
+ Then Stdout contains "1 fact(s) deleted"
14
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.26'
29
+ s.version = '0.0.27'
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.23'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.27'
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,51 @@
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 'backtrace'
24
+ require 'factbase/looged'
25
+ require_relative '../../judges'
26
+ require_relative '../../judges/to_rel'
27
+ require_relative '../../judges/packs'
28
+ require_relative '../../judges/options'
29
+ require_relative '../../judges/impex'
30
+
31
+ # Eval.
32
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
34
+ # License:: MIT
35
+ class Judges::Eval
36
+ def initialize(loog)
37
+ @loog = loog
38
+ end
39
+
40
+ def run(_opts, args)
41
+ raise 'Exactly two arguments required' unless args.size == 2
42
+ 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)
50
+ end
51
+ end
@@ -39,5 +39,6 @@ class Judges::Join
39
39
  fb = master.import
40
40
  slave.import_to(fb)
41
41
  master.export(fb)
42
+ @loog.info('Two factbases joined')
42
43
  end
43
44
  end
@@ -39,6 +39,7 @@ class Judges::Print
39
39
  o = args[1]
40
40
  f = args[0]
41
41
  fb = Judges::Impex.new(@loog, f).import
42
+ fb.query("(not #{opts['query']})").delete! unless opts['query'].nil?
42
43
  if o.nil?
43
44
  raise 'Either provide output file name or use --auto' unless opts[:auto]
44
45
  o = File.join(File.dirname(f), File.basename(f).gsub(/\.[^.]*$/, ''))
@@ -48,11 +49,14 @@ class Judges::Print
48
49
  output =
49
50
  case opts[:format].downcase
50
51
  when 'yaml'
51
- fb.to_yaml
52
+ require 'factbase/to_yaml'
53
+ Factbase::ToYAML.new(fb).yaml
52
54
  when 'json'
53
- fb.to_json
55
+ require 'factbase/to_json'
56
+ Factbase::ToJSON.new(fb).json
54
57
  when 'xml'
55
- fb.to_xml
58
+ require 'factbase/to_xml'
59
+ Factbase::ToXML.new(fb).xml
56
60
  end
57
61
  File.binwrite(o, output)
58
62
  @loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)")
@@ -24,6 +24,7 @@ require 'nokogiri'
24
24
  require 'factbase'
25
25
  require 'backtrace'
26
26
  require 'factbase/looged'
27
+ require 'factbase/to_xml'
27
28
  require_relative '../../judges'
28
29
  require_relative '../../judges/to_rel'
29
30
  require_relative '../../judges/packs'
@@ -95,7 +96,7 @@ class Judges::Test
95
96
  end
96
97
  end
97
98
  pack.run(Factbase::Looged.new(fb, @loog), global, local, Judges::Options.new(yaml['options']))
98
- xml = Nokogiri::XML.parse(fb.to_xml)
99
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
99
100
  yaml['expected'].each do |xp|
100
101
  raise "#{pack.script} doesn't match '#{xp}':\n#{xml}" if xml.xpath(xp).empty?
101
102
  end
@@ -37,13 +37,20 @@ class Judges::Trim
37
37
  raise 'Exactly one argument required' unless args.size == 1
38
38
  impex = Judges::Impex.new(@loog, args[0])
39
39
  fb = impex.import
40
- days = opts['days']
41
- day = Time.now - (days * 60 * 60 * 24)
42
- deleted = fb.query("(lt time #{day.utc.iso8601})").delete!
40
+ query = opts['query']
41
+ if query.nil?
42
+ days = opts['days']
43
+ day = Time.now - (days * 60 * 60 * 24)
44
+ query = "(lt time #{day.utc.iso8601})"
45
+ @loog.info("Deleting facts that are older than #{days} days")
46
+ else
47
+ raise 'Specify either --days or --query' unless opts['days'].nil?
48
+ end
49
+ deleted = fb.query(query).delete!
43
50
  if deleted.zero?
44
51
  @loog.info('No facts deleted')
45
52
  else
46
- @loog.info("🗑 #{deleted} fact(s) deleted, because they were older than #{days} days")
53
+ @loog.info("🗑 #{deleted} fact(s) deleted")
47
54
  impex.export(fb)
48
55
  end
49
56
  end
@@ -0,0 +1,45 @@
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/eval'
29
+
30
+ # Test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # License:: MIT
34
+ class TestEval < Minitest::Test
35
+ def test_build_factbase_from_scratch
36
+ Dir.mktmpdir do |d|
37
+ file = File.join(d, 'base.fb')
38
+ Judges::Eval.new(Loog::VERBOSE).run({}, [file, '$fb.insert.foo = 42'])
39
+ fb = Factbase.new
40
+ fb.import(File.binread(file))
41
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
42
+ assert(!xml.xpath('/fb/f[foo="42"]').empty?, xml)
43
+ end
44
+ end
45
+ end
@@ -23,6 +23,7 @@
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
25
  require 'nokogiri'
26
+ require 'factbase/to_xml'
26
27
  require_relative '../../lib/judges'
27
28
  require_relative '../../lib/judges/commands/join'
28
29
 
@@ -44,9 +45,9 @@ class TestJoin < Minitest::Test
44
45
  Judges::Join.new(Loog::VERBOSE).run({}, [master, slave])
45
46
  fb = Factbase.new
46
47
  fb.import(File.binread(master))
47
- xml = Nokogiri::XML.parse(fb.to_xml)
48
- assert(!xml.xpath('/fb/f[zz="5"]').empty?, fb.to_xml)
49
- assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, fb.to_xml)
48
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
49
+ assert(!xml.xpath('/fb/f[zz="5"]').empty?, xml)
50
+ assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, xml)
50
51
  end
51
52
  end
52
53
  end
@@ -23,6 +23,7 @@
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
25
  require 'nokogiri'
26
+ require 'factbase/to_xml'
26
27
  require_relative '../../lib/judges'
27
28
  require_relative '../../lib/judges/commands/update'
28
29
 
@@ -38,8 +39,8 @@ class TestUpdate < Minitest::Test
38
39
  Judges::Update.new(Loog::VERBOSE).run({ 'option' => ['foo_bar=42'] }, [d, file])
39
40
  fb = Factbase.new
40
41
  fb.import(File.binread(file))
41
- xml = Nokogiri::XML.parse(fb.to_xml)
42
- assert(!xml.xpath('/fb/f[zzz="43"]').empty?)
42
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
43
+ assert(!xml.xpath('/fb/f[zzz="43"]').empty?, xml)
43
44
  end
44
45
  end
45
46
 
@@ -53,9 +54,9 @@ class TestUpdate < Minitest::Test
53
54
  Judges::Update.new(Loog::VERBOSE).run({ 'max-cycles' => 1 }, [d, file])
54
55
  fb = Factbase.new
55
56
  fb.import(File.binread(file))
56
- xml = Nokogiri::XML.parse(fb.to_xml)
57
- assert(!xml.xpath('/fb/f[tt="4"]').empty?)
58
- assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?)
57
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
58
+ assert(!xml.xpath('/fb/f[tt="4"]').empty?, xml)
59
+ assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, xml)
59
60
  end
60
61
  end
61
62
 
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.26
4
+ version: 0.0.27
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-17 00:00:00.000000000 Z
11
+ date: 2024-05-19 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.23
33
+ version: 0.0.27
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.23
40
+ version: 0.0.27
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,7 @@ files:
114
114
  - bin/judges
115
115
  - features/gem_package.feature
116
116
  - features/inspect.feature
117
+ - features/join.feature
117
118
  - features/misc.feature
118
119
  - features/print.feature
119
120
  - features/step_definitions/steps.rb
@@ -127,6 +128,7 @@ files:
127
128
  - fixtures/reward_for_good_bug/simple-reward.yml
128
129
  - judges.gemspec
129
130
  - lib/judges.rb
131
+ - lib/judges/commands/eval.rb
130
132
  - lib/judges/commands/inspect.rb
131
133
  - lib/judges/commands/join.rb
132
134
  - lib/judges/commands/print.rb
@@ -141,6 +143,7 @@ files:
141
143
  - lib/judges/packs.rb
142
144
  - lib/judges/to_rel.rb
143
145
  - renovate.json
146
+ - test/commands/test_eval.rb
144
147
  - test/commands/test_inspect.rb
145
148
  - test/commands/test_join.rb
146
149
  - test/commands/test_print.rb