judges 0.0.29 → 0.0.30

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: e4506ff0fe002c7bd8077f203ba8a0af5b9d5b9b788e1d42370c6f990d4b9479
4
- data.tar.gz: 8cf313cdaa8a859ffe1c286107c767aac93a0196420152c57337dd05d0ed4881
3
+ metadata.gz: 2966161948e1ac2ed8c36b5f0e515183a9f8ea02d6ddabf396e7bd5db98ca787
4
+ data.tar.gz: 227712553b74473211e835d5c1df9afbf03e00d8942639d137fea6d98d40a236
5
5
  SHA512:
6
- metadata.gz: f19785b0268c7dce59b6d9478137e2e2e1172ebc03fd803b576d0c1d155eecadea11d38ecaa258f8ecefef031e183807660dee7b0f7aede0c875a42f101ae62d
7
- data.tar.gz: 433e49e718acd4b17ba9efdbce605181ca2b6cd88a7a36601bf71dc926f07185f652d57e1005750b28fe2c98467f05c1b93ddd93dee4461dd40f28a58a209097
6
+ metadata.gz: 120d2cec10fbca12aa6a9107ea348236dd44e999a8499dbef93952cb2fb313ea11bb67c658d0ebb6b6ee4f002383d2f8177d75d06bd8cb01d547032222e6b9aa
7
+ data.tar.gz: 3cf907ef01704e0e11ffa8313226420536436571ab11ea9a25cf4d8c7cbc98e334cbb7e193ea5994910c36c20dcf29d0ae1d1fee040cefca9c7b5d2c0ec91a33
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.28)
6
+ factbase (~> 0.0.29)
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.28)
77
+ factbase (0.0.29)
78
78
  json (~> 2.7)
79
79
  loog (~> 0.2)
80
80
  nokogiri (~> 1.10)
data/Rakefile CHANGED
@@ -69,6 +69,7 @@ end
69
69
  task :copyright do
70
70
  sh "grep -q -r '#{Date.today.strftime('%Y')}' \
71
71
  --include '*.rb' \
72
+ --include '*.yml' \
72
73
  --include '*.txt' \
73
74
  --include 'Rakefile' \
74
75
  ."
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.29'
35
+ ver = '0.0.30'
36
36
 
37
37
  loog = Loog::REGULAR
38
38
 
@@ -115,6 +115,8 @@ class App
115
115
  c.switch([:auto], default_value: false)
116
116
  c.desc 'Only the facts that match the expression are printed'
117
117
  c.flag([:query], default_value: '()')
118
+ c.desc 'Print even if target file already exists and is older than the factbase'
119
+ c.switch([:force], default_value: false)
118
120
  c.action do |global, options, args|
119
121
  require_relative '../lib/judges/commands/print'
120
122
  Judges::Print.new(loog).run(options, args)
@@ -4,7 +4,6 @@ Feature: Print
4
4
  Scenario: Simple print of a small factbase, to YAML
5
5
  Given I make a temp directory
6
6
  Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
7
- Then I run bin/judges with "update . simple.fb"
8
7
  Then I run bin/judges with "print --format=yaml simple.fb simple.yml"
9
8
  Then Stdout contains "printed"
10
9
  And Exit code is zero
@@ -12,7 +11,6 @@ Feature: Print
12
11
  Scenario: Simple print of a small factbase, to JSON
13
12
  Given I make a temp directory
14
13
  Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
15
- Then I run bin/judges with "update . simple.fb"
16
14
  Then I run bin/judges with "print --format=json simple.fb simple.json"
17
15
  Then Stdout contains "printed"
18
16
  And Exit code is zero
@@ -20,7 +18,6 @@ Feature: Print
20
18
  Scenario: Simple print of a small factbase, to XML
21
19
  Given I make a temp directory
22
20
  Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
23
- Then I run bin/judges with "update . simple.fb"
24
21
  Then I run bin/judges with "print --format=xml --auto simple.fb"
25
22
  Then Stdout contains "printed"
26
23
  And Exit code is zero
@@ -29,7 +26,15 @@ Feature: Print
29
26
  Given I make a temp directory
30
27
  Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
31
28
  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
29
  Then I run bin/judges with "print '--query=(eq foo 43)' --auto simple.fb"
34
30
  Then Stdout contains "printed"
35
31
  And Exit code is zero
32
+
33
+ Scenario: Print twice, without --force
34
+ Given I make a temp directory
35
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
36
+ Then I run bin/judges with "print --auto simple.fb"
37
+ Then Stdout contains "printed"
38
+ Then I run bin/judges with "print --auto simple.fb"
39
+ Then Stdout contains "No need to print"
40
+ 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.29'
29
+ s.version = '0.0.30'
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.28'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.29'
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'
@@ -40,6 +40,7 @@ class Judges::Import
40
40
  raise "File not found #{args[0].to_rel}" unless File.exist?(args[0])
41
41
  start = Time.now
42
42
  yaml = YAML.load_file(args[0], permitted_classes: [Time])
43
+ @loog.info("YAML loaded from #{args[0].to_rel} (#{yaml.size} facts)")
43
44
  impex = Judges::Impex.new(@loog, args[1])
44
45
  fb = impex.import(strict: false)
45
46
  fb = Factbase::Looged.new(fb, @loog)
@@ -36,16 +36,24 @@ class Judges::Print
36
36
 
37
37
  def run(opts, args)
38
38
  raise 'At lease one argument required' if args.empty?
39
- o = args[1]
40
39
  f = args[0]
41
40
  fb = Judges::Impex.new(@loog, f).import
42
41
  fb.query("(not #{opts['query']})").delete! unless opts['query'].nil?
42
+ o = args[1]
43
43
  if o.nil?
44
44
  raise 'Either provide output file name or use --auto' unless opts[:auto]
45
45
  o = File.join(File.dirname(f), File.basename(f).gsub(/\.[^.]*$/, ''))
46
46
  o = "#{o}.#{opts[:format]}"
47
47
  end
48
48
  FileUtils.mkdir_p(File.dirname(o))
49
+ if !opts['force'] && File.exist?(o)
50
+ if File.mtime(f) < File.mtime(o)
51
+ @loog.info("No need to print to #{o.to_rel}, since it's up to date (#{File.size(o)} bytes)")
52
+ return
53
+ end
54
+ @loog.debug("The factbase #{f.to_rel} is younger than the target #{o.to_rel}, need to print")
55
+ end
56
+ start = Time.now
49
57
  output =
50
58
  case opts[:format].downcase
51
59
  when 'yaml'
@@ -59,6 +67,6 @@ class Judges::Print
59
67
  Factbase::ToXML.new(fb).xml
60
68
  end
61
69
  File.binwrite(o, output)
62
- @loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)")
70
+ @loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes) in #{format('%.02f', Time.now - start)}s")
63
71
  end
64
72
  end
@@ -44,4 +44,19 @@ class TestPrint < Minitest::Test
44
44
  assert_equal(1, YAML.load_file(y)['facts'].size)
45
45
  end
46
46
  end
47
+
48
+ def test_print_twice
49
+ Dir.mktmpdir do |d|
50
+ f = File.join(d, 'base.fb')
51
+ fb = Factbase.new
52
+ fb.insert
53
+ File.binwrite(f, fb.export)
54
+ Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
55
+ y = File.join(d, 'base.yaml')
56
+ assert(File.exist?(y))
57
+ mtime = File.mtime(y)
58
+ Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
59
+ assert_equal(mtime, File.mtime(y))
60
+ end
61
+ end
47
62
  end
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.29
4
+ version: 0.0.30
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-19 00:00:00.000000000 Z
11
+ date: 2024-05-21 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.28
33
+ version: 0.0.29
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.28
40
+ version: 0.0.29
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement