judges 0.15.3 → 0.15.4

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: c55f53ae0053a336a2f35c02046a4def974a981bde802c79472db1692ff76e34
4
- data.tar.gz: 0d6eff130d9e2fe484427341e31c55087d4d31aa5cd44d88bd8cbec866b4c836
3
+ metadata.gz: 4b319a8d9796217efe6c3f17eda8dff446309527fdb1fa8bcf5eff2b8e49cdc7
4
+ data.tar.gz: 7d49b8b47d90c975095d6b449467bf4d77e630a1722a00217e355c1ac0cdf930
5
5
  SHA512:
6
- metadata.gz: f83f3a441a93594460592a1b5052d1f76b720fe0ce3b5f6d4b4834093c4092e3689407983aaa7009a285628ae25d606ba23defb098b0f11085a28010cd1ac3c5
7
- data.tar.gz: f19e035da56f053efbef01065040d85018834538785ac6dca4c10536e0e65f7d8dd85cc3097e86fe73d49f8c00a89b53930f6571c4814cbe44c2234efc1de443
6
+ metadata.gz: 38d655fb2487146e02aaa8e6b46f94c15fb37d54713f89588319c61864e4134fa9b6b02faca7686c4dfb2e6522fc5c904363ccabc19f456acb97ee2a8902449c
7
+ data.tar.gz: b145f0fa4018c72269cd4709f4d11bfe6d29e6d56be78db9da25fdcfa4d588cec294b51c7dec094c356d908b9c6d8a725efeea5e2028fdb183ae220651796c6f
data/Gemfile CHANGED
@@ -27,10 +27,11 @@ gem 'cucumber', '9.2.0', require: false
27
27
  gem 'minitest', '5.24.1', require: false
28
28
  gem 'net-ping', '2.0.8', require: false
29
29
  gem 'rake', '13.2.1', require: false
30
+ gem 'random-port', '~>0.0', require: false
30
31
  gem 'rspec-rails', '6.1.3', require: false
31
32
  gem 'rubocop', '1.64.1', require: false
32
33
  gem 'rubocop-performance', '1.21.1', require: false
33
- gem 'rubocop-rspec', '3.0.1', require: false
34
+ gem 'rubocop-rspec', '3.0.2', require: false
34
35
  gem 'simplecov', '0.22.0', require: false
35
36
  gem 'simplecov-cobertura', '2.1.0', require: false
36
37
  gem 'webmock', '3.23.1', require: false
data/Gemfile.lock CHANGED
@@ -110,7 +110,7 @@ GEM
110
110
  i18n (1.14.5)
111
111
  concurrent-ruby (~> 1.0)
112
112
  io-console (0.7.2)
113
- irb (1.13.2)
113
+ irb (1.14.0)
114
114
  rdoc (>= 4.0.0)
115
115
  reline (>= 0.4.2)
116
116
  iri (0.8.0)
@@ -174,6 +174,7 @@ GEM
174
174
  zeitwerk (~> 2.6)
175
175
  rainbow (3.1.1)
176
176
  rake (13.2.1)
177
+ random-port (0.7.0)
177
178
  rdoc (6.7.0)
178
179
  psych (>= 4.0.0)
179
180
  regexp_parser (2.9.2)
@@ -215,7 +216,7 @@ GEM
215
216
  rubocop-performance (1.21.1)
216
217
  rubocop (>= 1.48.1, < 2.0)
217
218
  rubocop-ast (>= 1.31.1, < 2.0)
218
- rubocop-rspec (3.0.1)
219
+ rubocop-rspec (3.0.2)
219
220
  rubocop (~> 1.61)
220
221
  ruby-progressbar (1.13.0)
221
222
  simplecov (0.22.0)
@@ -262,10 +263,11 @@ DEPENDENCIES
262
263
  minitest (= 5.24.1)
263
264
  net-ping (= 2.0.8)
264
265
  rake (= 13.2.1)
266
+ random-port (~> 0.0)
265
267
  rspec-rails (= 6.1.3)
266
268
  rubocop (= 1.64.1)
267
269
  rubocop-performance (= 1.21.1)
268
- rubocop-rspec (= 3.0.1)
270
+ rubocop-rspec (= 3.0.2)
269
271
  simplecov (= 0.22.0)
270
272
  simplecov-cobertura (= 2.1.0)
271
273
  webmock (= 3.23.1)
data/assets/index.xsl CHANGED
@@ -40,7 +40,14 @@ SOFTWARE.
40
40
  <head>
41
41
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
42
42
  <title>
43
- <xsl:value-of select="$title"/>
43
+ <xsl:choose>
44
+ <xsl:when test="$title = ''">
45
+ <xsl:text>factbase</xsl:text>
46
+ </xsl:when>
47
+ <xsl:otherwise>
48
+ <xsl:value-of select="$title"/>
49
+ </xsl:otherwise>
50
+ </xsl:choose>
44
51
  </title>
45
52
  <meta charset="UTF-8"/>
46
53
  <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
@@ -170,8 +177,8 @@ SOFTWARE.
170
177
  <td>
171
178
  <xsl:for-each select="$f/*">
172
179
  <xsl:text> </xsl:text>
173
- <xsl:variable name="visible" select="string-length(substring-before(concat(',', $hidden, ','), concat(name(), ','))) = 0"/>
174
- <xsl:if test="string-length(substring-before(concat(',', $columns, ','), concat(name(), ','))) = 0">
180
+ <xsl:variable name="visible" select="string-length(substring-before(concat(',', $hidden, ','), concat(',', name(), ','))) = 0"/>
181
+ <xsl:if test="string-length(substring-before(concat(',', $columns, ','), concat(',', name(), ','))) = 0">
175
182
  <xsl:choose>
176
183
  <xsl:when test="$visible">
177
184
  <xsl:value-of select="name()"/>
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.15.3'
29
+ s.version = '0.15.4'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
data/lib/judges/baza.rb CHANGED
@@ -160,12 +160,14 @@ class Judges::Baza
160
160
  def name_exists?(name)
161
161
  exists = 0
162
162
  elapsed(@loog) do
163
- ret = checked(
164
- Typhoeus::Request.get(
165
- home.append('exists').append(name).to_s,
166
- headers:
163
+ ret = with_retries do
164
+ checked(
165
+ Typhoeus::Request.get(
166
+ home.append('exists').append(name).to_s,
167
+ headers:
168
+ )
167
169
  )
168
- )
170
+ end
169
171
  exists = ret.body == 'yes'
170
172
  throw :"The name \"#{name}\" #{exists ? 'exists' : "doesn't exist"} at #{@host}"
171
173
  end
@@ -176,9 +178,9 @@ class Judges::Baza
176
178
 
177
179
  def headers
178
180
  {
179
- 'User-Agent': "judges #{Judges::VERSION}",
180
- Connection: 'close',
181
- 'X-Zerocracy-Token': @token
181
+ 'User-Agent' => "judges #{Judges::VERSION}",
182
+ 'Connection' => 'close',
183
+ 'X-Zerocracy-Token' => @token
182
184
  }
183
185
  end
184
186
 
@@ -43,6 +43,7 @@ class Judges::Update
43
43
  raise 'Exactly two arguments required' unless args.size == 2
44
44
  dir = args[0]
45
45
  raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir)
46
+ start = Time.now
46
47
  impex = Judges::Impex.new(@loog, args[1])
47
48
  fb = impex.import(strict: false)
48
49
  fb = Factbase::Looged.new(fb, @loog) if opts['log']
@@ -82,6 +83,7 @@ class Judges::Update
82
83
  f.what = 'judges-summary'
83
84
  f.when = Time.now
84
85
  f.version = Judges::VERSION
86
+ f.seconds = Time.now - start
85
87
  f.cycles = c
86
88
  f.added = churn.added.size
87
89
  f.removed = churn.removed.size
data/lib/judges/impex.rb CHANGED
@@ -24,6 +24,7 @@ require 'factbase'
24
24
  require 'fileutils'
25
25
  require_relative '../judges'
26
26
  require_relative '../judges/to_rel'
27
+ require_relative '../judges/elapsed'
27
28
 
28
29
  # Import/Export of factbases.
29
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -38,8 +39,10 @@ class Judges::Impex
38
39
  def import(strict: true)
39
40
  fb = Factbase.new
40
41
  if File.exist?(@file)
41
- fb.import(File.binread(@file))
42
- @loog.info("The factbase imported from #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)")
42
+ elapsed(@loog) do
43
+ fb.import(File.binread(@file))
44
+ throw :"The factbase imported from #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)"
45
+ end
43
46
  else
44
47
  raise "The factbase is absent at #{@file.to_rel}" if strict
45
48
  @loog.info("Nothing to import from #{@file.to_rel} (file not found)")
@@ -49,13 +52,17 @@ class Judges::Impex
49
52
 
50
53
  def import_to(fb)
51
54
  raise "The factbase is absent at #{@file.to_rel}" unless File.exist?(@file)
52
- fb.import(File.binread(@file))
53
- @loog.info("The factbase loaded from #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)")
55
+ elapsed(@loog) do
56
+ fb.import(File.binread(@file))
57
+ throw :"The factbase loaded from #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)"
58
+ end
54
59
  end
55
60
 
56
61
  def export(fb)
57
- FileUtils.mkdir_p(File.dirname(@file))
58
- File.binwrite(@file, fb.export)
59
- @loog.info("Factbase exported to #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)")
62
+ elapsed(@loog) do
63
+ FileUtils.mkdir_p(File.dirname(@file))
64
+ File.binwrite(@file, fb.export)
65
+ throw :"Factbase exported to #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)"
66
+ end
60
67
  end
61
68
  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.15.3'
28
+ VERSION = '0.15.4'
29
29
  end
@@ -92,8 +92,9 @@ class TestUpdate < Minitest::Test
92
92
  fb.import(File.binread(file))
93
93
  sums = fb.query('(eq what "judges-summary")').each.to_a
94
94
  assert_equal(1, sums.size)
95
- f = sums.first
96
- assert(f.error.include?('unexpected global variable'), f.error)
95
+ sum = sums.first
96
+ assert(sum.error.include?('unexpected global variable'), sum.error)
97
+ assert(!sum.seconds.nil?)
97
98
  end
98
99
  end
99
100
  end
data/test/test_baza.rb CHANGED
@@ -23,6 +23,8 @@
23
23
  require 'minitest/autorun'
24
24
  require 'webmock/minitest'
25
25
  require 'loog'
26
+ require 'socket'
27
+ require 'random-port'
26
28
  require_relative '../lib/judges'
27
29
  require_relative '../lib/judges/baza'
28
30
 
@@ -44,9 +46,9 @@ class TestBaza < Minitest::Test
44
46
 
45
47
  def test_simple_recent_check
46
48
  WebMock.disable_net_connect!
47
- stub_request(:get, 'https://example.org/recent/simple.txt').to_return(
48
- status: 200, body: '42'
49
- )
49
+ stub_request(:get, 'https://example.org/recent/simple.txt')
50
+ .with(body: '', headers: { 'User-Agent' => /^judges .*$/ })
51
+ .to_return(status: 200, body: '42')
50
52
  assert_equal(
51
53
  42,
52
54
  Judges::Baza.new('example.org', 443, '000').recent('simple')
@@ -72,4 +74,26 @@ class TestBaza < Minitest::Test
72
74
  Judges::Baza.new('example.org', 443, '000').pull(333).start_with?('hello')
73
75
  )
74
76
  end
77
+
78
+ def test_real_http
79
+ WebMock.enable_net_connect!
80
+ req = []
81
+ host = '127.0.0.1'
82
+ RandomPort::Pool::SINGLETON.acquire do |port|
83
+ server = TCPServer.new(host, port)
84
+ t = Thread.new do
85
+ socket = server.accept
86
+ loop do
87
+ line = socket.gets
88
+ break if line == "\r\n"
89
+ req << line
90
+ end
91
+ socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nyes"
92
+ socket.close
93
+ end
94
+ Judges::Baza.new(host, port, '0000', ssl: false, timeout: 1).name_exists?('simple')
95
+ t.join
96
+ end
97
+ assert(req.include?("User-Agent: judges #{Judges::VERSION}\r\n"))
98
+ end
75
99
  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.15.3
4
+ version: 0.15.4
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-07-03 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace