judges 0.13.0 → 0.13.2

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: '098f6126af6c35b9ee74dca41bbfb5b8e6b1357aee5dcec215a2819929e859d5'
4
- data.tar.gz: 139a4b55ea82a090e385c4f54be682dd74d0922c66d77824c8d33cecaa799a84
3
+ metadata.gz: 423404090687b2214385439c28e9d5aa3e916d3eab7fcad7b406e9c795750ed0
4
+ data.tar.gz: 8f5c5b7f86625a2d57f3419010ea06891ca34ae3e1332a6858bd0f3edd467f8f
5
5
  SHA512:
6
- metadata.gz: 0e173739bc5341c55f869375fef959ff9e6ca57c1e0b814a29d4920700f640fc788a948932221c9fbf6f9e7d9d90501e274645f3de213b7f9b3211549652ad1c
7
- data.tar.gz: 52f4c44351e5f3c9efb873913f26c8a7c2c5c08dbf490434145cc691968eec240ef95bb5007568b623c043f48ab658624a573664598df587282cb1cfb43ef94b
6
+ metadata.gz: 56b32e90fb490e8664960b113b1f4aea5ff8b5be8778aab308c3d2cfdfade484d1efbe1550f523303ff8372f6065dd581ad01c19a2b48e38b4b250052ae74332
7
+ data.tar.gz: '0578ac5a5a17b870e887e7ba6aaafafdaf51ad02b3d32fbb77857718b427550419e04c5d9711e907f2cb2b6eb7c35d58a0b5f4bc3ead36854fe6f5733c90bb8c'
@@ -9,8 +9,8 @@ Feature: Update
9
9
  n.kind = 'yes!'
10
10
  """
11
11
  Then I run bin/judges with "--verbose update --quiet -o foo=1 -o bar=2 --max-cycles 3 . simple.fb"
12
- Then Stdout contains "foo → "
13
- Then Stdout contains "bar → "
12
+ Then Stdout contains "FOO → "
13
+ Then Stdout contains "BAR → "
14
14
  Then Stdout contains "1 judge(s) processed"
15
15
  Then Stdout contains "Update finished in 3 cycle(s), modified 3/0 fact(s)"
16
16
  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.13.0'
29
+ s.version = '0.13.2'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
@@ -47,7 +47,11 @@ class Judges::Update
47
47
  fb = impex.import(strict: false)
48
48
  fb = Factbase::Looged.new(fb, @loog) if opts['log']
49
49
  options = Judges::Options.new(opts['option'])
50
- @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
50
+ if options.empty?
51
+ @loog.debug('No options provided by the --option flag')
52
+ else
53
+ @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
54
+ end
51
55
  judges = Judges::Judges.new(dir, opts['lib'], @loog)
52
56
  c = 0
53
57
  churn = Judges::Churn.new(0, 0)
@@ -34,43 +34,54 @@ class Judges::Options
34
34
  @pairs = pairs
35
35
  end
36
36
 
37
+ def empty?
38
+ to_h.empty?
39
+ end
40
+
37
41
  def +(other)
38
- touch # this will trigger method_missing() method, which will create @hash
39
- h = @hash.dup
40
- other.touch # this will trigger method_missing() method, which will create @hash
41
- other.instance_variable_get(:@hash).each do |k, v|
42
+ h = to_h
43
+ other.to_h.each do |k, v|
42
44
  h[k] = v
43
45
  end
44
- Judges::Options.new(h.map { |k, v| "#{k}=#{v}" })
46
+ Judges::Options.new(h)
45
47
  end
46
48
 
47
49
  # Convert them all to a string (printable in a log).
48
50
  def to_s
49
- touch # this will trigger method_missing() method, which will create @hash
50
- @hash.map do |k, v|
51
+ to_h.map do |k, v|
51
52
  v = v.to_s
52
53
  v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
53
54
  "#{k} → \"#{v}\""
54
55
  end.join("\n")
55
56
  end
56
57
 
57
- # Get option by name.
58
- others do |*args|
59
- @hash ||= begin
58
+ def to_h
59
+ @to_h ||= begin
60
60
  pp = @pairs || []
61
- pp = @pairs.map { |k, v| "#{k}=#{v}" } if pp.is_a?(Hash)
62
61
  pp = pp.split(',') if pp.is_a?(String)
63
- pp.compact!
64
- pp.reject!(&:empty?)
65
- pp.to_h do |pair|
66
- p = pair.split('=', 2)
67
- k = p[0].strip
68
- v = p[1]
69
- v = v.nil? ? 'true' : v.strip
70
- [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
71
71
  end
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 }
72
80
  end
73
- k = args[0].downcase
74
- @hash[k]
81
+ end
82
+
83
+ # Get option by name.
84
+ others do |*args|
85
+ to_h[args[0].upcase.to_sym]
75
86
  end
76
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.0'
28
+ VERSION = '0.13.2'
29
29
  end
data/test/test_options.rb CHANGED
@@ -41,19 +41,27 @@ class TestOptions < Minitest::Test
41
41
  assert_equal(42, opts.max)
42
42
  end
43
43
 
44
+ def test_case_insensitive
45
+ opts = Judges::Options.new(['aBcDeF=1', 'aBCDEf=2'])
46
+ assert_equal(2, opts.abcdef)
47
+ end
48
+
44
49
  def test_with_nil
45
50
  opts = Judges::Options.new(nil)
46
51
  assert(opts.foo.nil?)
52
+ assert(opts.empty?)
47
53
  end
48
54
 
49
55
  def test_with_empty_string
50
56
  opts = Judges::Options.new(' ')
51
57
  assert(opts.foo.nil?)
58
+ assert(opts.empty?, opts)
52
59
  end
53
60
 
54
61
  def test_with_empty_strings
55
62
  opts = Judges::Options.new(['', nil])
56
63
  assert(opts.foo.nil?)
64
+ assert(opts.empty?)
57
65
  end
58
66
 
59
67
  def test_with_string
@@ -65,14 +73,14 @@ class TestOptions < Minitest::Test
65
73
  def test_with_hash
66
74
  opts = Judges::Options.new('foo' => 42, 'bar' => 'hello')
67
75
  assert_equal(42, opts.foo)
68
- assert_equal('hello', opts.bar)
76
+ assert_equal('hello', opts.Bar)
69
77
  assert(opts.xxx.nil?)
70
78
  end
71
79
 
72
80
  def test_converts_to_string
73
81
  opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
74
82
  s = opts.to_s
75
- assert(s.include?('foo → "44"'))
83
+ assert(s.include?('FOO → "44"'), s)
76
84
  assert(s.include?('"long********************"'))
77
85
  end
78
86
 
@@ -83,4 +91,10 @@ class TestOptions < Minitest::Test
83
91
  assert_equal(44, opts.a)
84
92
  assert_equal(3, opts.c)
85
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
86
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.0
4
+ version: 0.13.2
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-26 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace