fbe 0.28.1 → 0.29.0

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: 25b95f924ac73210555c91b1102ab632a0ad478b843a4c0e13d8aad5ea193d3a
4
- data.tar.gz: 4b9c39ac83710018b43edb06963e1bf5bf27f9800b64a19bd51986d0611295d3
3
+ metadata.gz: f217bdf737550a6a1dc1ffe033e3b4a731149b48f357ed5c2ad33b9fa81b2354
4
+ data.tar.gz: 220d01ad45a7c3f553cc29e2870faa9021b7a42a550e39883632aa8beddff4cb
5
5
  SHA512:
6
- metadata.gz: 9959047b9386598ba19232bc2101c97400bfee084c01d0cf5285f5ec84681cf2f1f39da10c7a88e09dcc705b87d45d03a38b9b529c64645fb6e8ba334727bf63
7
- data.tar.gz: 31ce58af7e239460b310afd89aa8c719c8984f73087233fda8c1d1453b7a836d19f3dddfea9ea9592b4a5a0de616be380c8791e201e37377265a2cc9f65606c9
6
+ metadata.gz: 943429b3e27f1c5a4c37ca67b6cf8731fe87b66665d094f5237821f780db7269487ac080bf8756561fa67954ae531276dcf0bed8f3a6b6cc0e4286d58ef699a3
7
+ data.tar.gz: a5e77f3f279f55aa784e25edf1f4f4aa8701852ee15ae30fdc4cab1f02d268c6d7b3343e32c76e352e1abf77687acbaae74033d75a92b0b9b3b0feee133c96d9
data/Gemfile.lock CHANGED
@@ -74,7 +74,7 @@ GEM
74
74
  loog (~> 0.6)
75
75
  tago (~> 0.1)
76
76
  ellipsized (0.3.0)
77
- ethon (0.17.0)
77
+ ethon (0.15.0)
78
78
  ffi (>= 1.15.0)
79
79
  factbase (0.15.6)
80
80
  backtrace (~> 0.4)
@@ -189,7 +189,7 @@ GEM
189
189
  regexp_parser (2.11.2)
190
190
  retries (0.0.5)
191
191
  rexml (3.4.2)
192
- rubocop (1.80.0)
192
+ rubocop (1.80.1)
193
193
  json (~> 2.3)
194
194
  language_server-protocol (~> 3.17.0.2)
195
195
  lint_roller (~> 1.1.0)
@@ -236,8 +236,8 @@ GEM
236
236
  tago (0.1.0)
237
237
  timeout (0.4.3)
238
238
  total (0.4.1)
239
- typhoeus (1.4.1)
240
- ethon (>= 0.9.0)
239
+ typhoeus (1.5.0)
240
+ ethon (>= 0.9.0, < 0.16.0)
241
241
  tzinfo (2.0.6)
242
242
  concurrent-ruby (~> 1.0)
243
243
  unicode-display_width (3.1.5)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require_relative '../fbe'
7
+ require_relative 'fb'
8
+
9
+ # Delete a few facts, knowing their IDs.
10
+ #
11
+ # @param [Array] facts List of facts to kill
12
+ # @param [Factbase] fb The factbase to use (defaults to Fbe.fb)
13
+ def Fbe.kill_if(facts, fb: Fbe.fb, fid: '_id')
14
+ ids = []
15
+ facts.each do |f|
16
+ if block_given?
17
+ t = yield f
18
+ next unless t
19
+ end
20
+ ids << f[fid].first
21
+ end
22
+ fb.query("(or #{ids.map { |id| "(eq #{fid} #{id})" }.join})").delete!
23
+ end
data/lib/fbe/tombstone.rb CHANGED
@@ -22,13 +22,15 @@ class Fbe::Tombstone
22
22
  end
23
23
 
24
24
  # Put it there.
25
+ # @param [String] where The place, e.g. "github"
25
26
  # @param [Integer] repo ID of repository
26
27
  # @param [Integer] issue ID of issue (or array of them)
27
- def bury!(repo, issue)
28
+ def bury!(where, repo, issue)
28
29
  f =
29
30
  Fbe.if_absent(fb: @fb, always: true) do |n|
30
31
  n.what = 'tombstone'
31
- n.repository = repo
32
+ n.where = where
33
+ n.repo = repo
32
34
  end
33
35
  f.send(:"#{@fid}=", SecureRandom.random_number(99_999)) if f[@fid].nil?
34
36
  nn = f['issues']&.map { |ii| ii.split('-').map(&:to_i) } || []
@@ -54,12 +56,13 @@ class Fbe::Tombstone
54
56
  end
55
57
 
56
58
  # Is it there?
59
+ # @param [String] where The place, e.g. "github"
57
60
  # @param [Integer] repo ID of repository
58
61
  # @param [Integer] issue ID of issue (or array of them)
59
62
  # @return [Boolean] True if it's there
60
- def has?(repo, issue)
63
+ def has?(where, repo, issue)
61
64
  f = @fb.query(
62
- "(and (eq what 'tombstone') (eq repository #{repo}) (exists issues))"
65
+ "(and (eq where '#{where}') (eq what 'tombstone') (eq repo #{repo}) (exists issues))"
63
66
  ).each.first
64
67
  return false if f.nil?
65
68
  issue = [issue] unless issue.is_a?(Array)
data/lib/fbe.rb CHANGED
@@ -10,5 +10,5 @@
10
10
  # License:: MIT
11
11
  module Fbe
12
12
  # Current version of the gem (changed by +.rultor.yml+ on every release)
13
- VERSION = '0.28.1' unless const_defined?(:VERSION)
13
+ VERSION = '0.29.0' unless const_defined?(:VERSION)
14
14
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Zerocracy
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'factbase'
7
+ require_relative '../../lib/fbe/fb'
8
+ require_relative '../../lib/fbe/kill_if'
9
+ require_relative '../test__helper'
10
+
11
+ # Test.
12
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
13
+ # Copyright:: Copyright (c) 2024-2025 Zerocracy
14
+ # License:: MIT
15
+ class TestKillIf < Fbe::Test
16
+ def test_deletes_a_few
17
+ fb = Factbase.new
18
+ f = fb.insert
19
+ f.foo = 42
20
+ f.hey = 4
21
+ f.id = 555
22
+ Fbe.kill_if([f], fb:, fid: 'id')
23
+ assert_equal(0, fb.size)
24
+ end
25
+
26
+ def test_deletes_with_a_block
27
+ fb = Factbase.new
28
+ fb.insert.then do |f|
29
+ f.foo = 0
30
+ f._id = 777
31
+ end
32
+ fb.insert.then do |f|
33
+ f.foo = 1
34
+ f._id = 778
35
+ end
36
+ assert_equal(1, Fbe.kill_if(fb.query('(always)').each.to_a, fb:) { |f| f.foo.zero? })
37
+ assert_equal(1, fb.size)
38
+ end
39
+ end
@@ -15,38 +15,42 @@ class TestTombstone < Fbe::Test
15
15
  def test_simple
16
16
  fb = Factbase.new
17
17
  ts = Fbe::Tombstone.new(fb:)
18
- ts.bury!(41, 13)
19
- ts.bury!(42, 13)
20
- ts.bury!(42, 999)
21
- assert(ts.has?(41, 13))
22
- assert(ts.has?(42, 999))
23
- refute(ts.has?(8, 7))
24
- refute(ts.has?(43, 999))
25
- refute(ts.has?(43, 990))
18
+ where = 'github'
19
+ ts.bury!(where, 41, 13)
20
+ ts.bury!(where, 42, 13)
21
+ ts.bury!(where, 42, 999)
22
+ assert(ts.has?(where, 41, 13))
23
+ assert(ts.has?(where, 42, 999))
24
+ refute(ts.has?(where, 8, 7))
25
+ refute(ts.has?(where, 43, 999))
26
+ refute(ts.has?(where, 43, 990))
26
27
  end
27
28
 
28
29
  def test_on_empty
29
30
  fb = Factbase.new
30
31
  ts = Fbe::Tombstone.new(fb:)
31
- refute(ts.has?(8, 7))
32
+ where = 'github'
33
+ refute(ts.has?(where, 8, 7))
32
34
  end
33
35
 
34
36
  def test_bury_twice
35
37
  fb = Factbase.new
36
38
  ts = Fbe::Tombstone.new(fb:)
37
- 2.times { ts.bury!(42, 7) }
38
- assert(ts.has?(42, 7))
39
+ where = 'github'
40
+ 2.times { ts.bury!(where, 42, 7) }
41
+ assert(ts.has?(where, 42, 7))
39
42
  end
40
43
 
41
44
  def test_merges_them
42
45
  fb = Factbase.new
43
46
  ts = Fbe::Tombstone.new(fb:)
44
- ts.bury!(42, 13)
45
- ts.bury!(42, 18)
46
- ts.bury!(42, 14)
47
- ts.bury!(42, [17, 15, 16])
48
- assert(ts.has?(42, 16))
49
- assert(ts.has?(42, [16, 18]))
50
- refute(ts.has?(42, 22))
47
+ where = 'github'
48
+ ts.bury!(where, 42, 13)
49
+ ts.bury!(where, 42, 18)
50
+ ts.bury!(where, 42, 14)
51
+ ts.bury!(where, 42, [17, 15, 16])
52
+ assert(ts.has?(where, 42, 16))
53
+ assert(ts.has?(where, 42, [16, 18]))
54
+ refute(ts.has?(where, 42, 22))
51
55
  end
52
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.1
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -376,6 +376,7 @@ files:
376
376
  - lib/fbe/issue.rb
377
377
  - lib/fbe/iterate.rb
378
378
  - lib/fbe/just_one.rb
379
+ - lib/fbe/kill_if.rb
379
380
  - lib/fbe/middleware.rb
380
381
  - lib/fbe/middleware/formatter.rb
381
382
  - lib/fbe/middleware/rate_limit.rb
@@ -409,6 +410,7 @@ files:
409
410
  - test/fbe/test_issue.rb
410
411
  - test/fbe/test_iterate.rb
411
412
  - test/fbe/test_just_one.rb
413
+ - test/fbe/test_kill_if.rb
412
414
  - test/fbe/test_octo.rb
413
415
  - test/fbe/test_overwrite.rb
414
416
  - test/fbe/test_pmp.rb