judges 0.13.1 → 0.13.3

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: 0e42894e95397d8b62afd1deaf3407d31321475e378f4ebdfd88216571ff742d
4
- data.tar.gz: d59aaa5f47aa2f7373b78e36869bc09aacd1c52f881c910c45d292407c3da203
3
+ metadata.gz: 9e76d1f282682fcc72f42108fbd6f74c8d8acd87961c3b5420bda5e44b0df1b3
4
+ data.tar.gz: dcb601124c359e0ede4dc01c6a5198237d311651401d9a39cb8eca4502146c01
5
5
  SHA512:
6
- metadata.gz: 1be5c4aad65f212b8bc700616851356ccf331be5b51a1ccc1e2d9d71e2225c8f648d0604e4ae5b1957d4b0623d43b8de6e78da2a8b1ed5ecdbbbe6db9eba3fc4
7
- data.tar.gz: 8174ac41e04c618635c868b06164b79939cc2891066bda8063f806f9395b8985a650eab5770fd778fe86ad7f42d8f9496f46331a3cff175d570f39d0af2e00a2
6
+ metadata.gz: 357ce5e3ef1099f0da69cc72d3ac2ba98c5375d44033dbc681cdc239b69432191459f683aa382266595260478dd9bfbd307b52c1ded41a3a044d11fd76026ebc
7
+ data.tar.gz: ab21e5e0d38183581a9bc3aa17b33c977079958db68f5483b1a144c65e7d9b82d7ade9999c2089dcb87d4c03e334d91d01a9cc3859e8b371d257ab992c678fb6
data/Gemfile.lock CHANGED
@@ -89,7 +89,7 @@ GEM
89
89
  erubi (1.13.0)
90
90
  ethon (0.16.0)
91
91
  ffi (>= 1.15.0)
92
- factbase (0.0.54)
92
+ factbase (0.0.56)
93
93
  backtrace (~> 0.3)
94
94
  decoor (~> 0.0)
95
95
  json (~> 2.7)
@@ -119,7 +119,7 @@ GEM
119
119
  loofah (2.22.0)
120
120
  crass (~> 1.0.2)
121
121
  nokogiri (>= 1.12.0)
122
- loog (0.5.1)
122
+ loog (0.5.2)
123
123
  mini_mime (1.1.5)
124
124
  minitest (5.24.0)
125
125
  moments (0.3.0)
@@ -19,8 +19,10 @@ Feature: Update
19
19
  Given I make a temp directory
20
20
  Then I have a "mine/judge1/simple_judge.rb" file with content:
21
21
  """
22
- n = $fb.insert
23
- n.foo = $foo
22
+ $valve.enter('boom') do
23
+ n = $fb.insert
24
+ n.foo = $foo
25
+ end
24
26
  """
25
27
  Then I have a "mylib/foo.rb" file with content:
26
28
  """
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.13.1'
29
+ s.version = '0.13.3'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
data/lib/judges/judge.rb CHANGED
@@ -45,6 +45,7 @@ class Judges::Judge
45
45
  $loog = @loog
46
46
  $global = global
47
47
  $local = local
48
+ $valve = FakeValve.new if $valve.nil?
48
49
  unless @lib.nil?
49
50
  raise "Lib dir #{@lib.to_rel} is absent" unless File.exist?(@lib)
50
51
  raise "Lib #{@lib.to_rel} is not a directory" unless File.directory?(@lib)
@@ -77,4 +78,11 @@ class Judges::Judge
77
78
  def tests
78
79
  Dir.glob(File.join(@dir, '*.yml'))
79
80
  end
81
+
82
+ # Fake valve.
83
+ class FakeValve
84
+ def enter(_)
85
+ yield
86
+ end
87
+ end
80
88
  end
@@ -35,48 +35,53 @@ class Judges::Options
35
35
  end
36
36
 
37
37
  def empty?
38
- touch # this will trigger method_missing() method, which will create @hash
39
- @hash.empty?
38
+ to_h.empty?
40
39
  end
41
40
 
42
41
  def +(other)
43
- touch # this will trigger method_missing() method, which will create @hash
44
- h = @hash.dup
45
- other.touch # this will trigger method_missing() method, which will create @hash
46
- other.instance_variable_get(:@hash).each do |k, v|
42
+ h = to_h
43
+ other.to_h.each do |k, v|
47
44
  h[k] = v
48
45
  end
49
- Judges::Options.new(h.map { |k, v| "#{k}=#{v}" })
46
+ Judges::Options.new(h)
50
47
  end
51
48
 
52
49
  # Convert them all to a string (printable in a log).
53
50
  def to_s
54
- touch # this will trigger method_missing() method, which will create @hash
55
- @hash.map do |k, v|
51
+ to_h.map do |k, v|
56
52
  v = v.to_s
57
53
  v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
58
54
  "#{k} → \"#{v}\""
59
55
  end.join("\n")
60
56
  end
61
57
 
62
- # Get option by name.
63
- others do |*args|
64
- @hash ||= begin
58
+ def to_h
59
+ @to_h ||= begin
65
60
  pp = @pairs || []
66
- pp = @pairs.map { |k, v| "#{k}=#{v}" } if pp.is_a?(Hash)
67
61
  pp = pp.split(',') if pp.is_a?(String)
68
- pp.compact!
69
- pp.reject!(&:empty?)
70
- pp.map! do |pair|
71
- p = pair.split('=', 2)
72
- k = p[0].strip.upcase
73
- v = p[1]
74
- v = v.nil? ? 'true' : v.strip
75
- [k.to_sym, v.match?(/^[0-9]+$/) ? v.to_i : v]
62
+ if pp.is_a?(Array)
63
+ pp = pp
64
+ .compact
65
+ .map(&:strip)
66
+ .reject(&:empty?)
67
+ .map { |s| s.split('=', 2) }
68
+ .map { |a| a.size == 1 ? [a[0], nil] : a }
69
+ .reject { |a| a[0].empty? }
70
+ .to_h
76
71
  end
77
- pp.reject { |p| p[0].empty? }.to_h
72
+ pp
73
+ .reject { |k, _| k.nil? }
74
+ .reject { |k, _| k.is_a?(String) && k.empty? }
75
+ .to_h
76
+ .transform_values { |v| v.nil? ? 'true' : v }
77
+ .transform_values { |v| v.is_a?(String) ? v.strip : v }
78
+ .transform_values { |v| v.is_a?(String) && v.match?(/^[0-9]+$/) ? v.to_i : v }
79
+ .transform_keys { |k| k.to_s.strip.upcase.to_sym }
78
80
  end
79
- k = args[0].upcase
80
- @hash[k]
81
+ end
82
+
83
+ # Get option by name.
84
+ others do |*args|
85
+ to_h[args[0].upcase.to_sym]
81
86
  end
82
87
  end
data/lib/judges.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Judges
28
- VERSION = '0.13.1'
28
+ VERSION = '0.13.3'
29
29
  end
data/test/test_options.rb CHANGED
@@ -55,7 +55,7 @@ class TestOptions < Minitest::Test
55
55
  def test_with_empty_string
56
56
  opts = Judges::Options.new(' ')
57
57
  assert(opts.foo.nil?)
58
- assert(opts.empty?)
58
+ assert(opts.empty?, opts)
59
59
  end
60
60
 
61
61
  def test_with_empty_strings
@@ -73,14 +73,14 @@ class TestOptions < Minitest::Test
73
73
  def test_with_hash
74
74
  opts = Judges::Options.new('foo' => 42, 'bar' => 'hello')
75
75
  assert_equal(42, opts.foo)
76
- assert_equal('hello', opts.bar)
76
+ assert_equal('hello', opts.Bar)
77
77
  assert(opts.xxx.nil?)
78
78
  end
79
79
 
80
80
  def test_converts_to_string
81
81
  opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
82
82
  s = opts.to_s
83
- assert(s.include?('FOO → "44"'))
83
+ assert(s.include?('FOO → "44"'), s)
84
84
  assert(s.include?('"long********************"'))
85
85
  end
86
86
 
@@ -91,4 +91,10 @@ class TestOptions < Minitest::Test
91
91
  assert_equal(44, opts.a)
92
92
  assert_equal(3, opts.c)
93
93
  end
94
+
95
+ def test_merge_by_symbols
96
+ opts = Judges::Options.new(a: 42) + Judges::Options.new(b: 7)
97
+ assert_equal(42, opts.a, opts)
98
+ assert_equal(7, opts.b, opts)
99
+ end
94
100
  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.13.1
4
+ version: 0.13.3
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-06-27 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace