Class: Fbe::Tombstone
- Inherits:
-
Object
- Object
- Fbe::Tombstone
- Defined in:
- lib/fbe/tombstone.rb
Overview
Checks whether an issue is already under a tombstone.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2026 Zerocracy
- License
-
MIT
Instance Method Summary collapse
-
#bury!(where, repo, issue) ⇒ Object
Put it there.
-
#has?(where, repo, issue) ⇒ Boolean
Is it there?.
-
#initialize(fb: Fbe.fb, fid: '_id') ⇒ Tombstone
constructor
Ctor.
-
#issues(where, repo) ⇒ Array<Integer>
See all issues in the tombstone, as array of numbers.
Constructor Details
Instance Method Details
#bury!(where, repo, issue) ⇒ Object
Put it there.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fbe/tombstone.rb', line 47 def bury!(where, repo, issue) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity raise(Fbe::Error, 'The type of "where" is not String') unless where.is_a?(String) raise(Fbe::Error, 'The type of "repo" is not Integer') unless repo.is_a?(Integer) unless issue.is_a?(Integer) || issue.is_a?(Array) raise(Fbe::Error, 'The type of "issue" is neither Integer nor Array') end f = Fbe.if_absent(fb: @fb, always: true) do |n| n.what = 'tombstone' n.where = where n.repository = repo end f.public_send(:"#{@fid}=", SecureRandom.random_number(99_999)) if f[@fid].nil? nn = f['issues']&.map do |ii| ii.split('-').map do |i| Integer(i, 10) end.then { |ii| ii.size == 1 ? ii << ii[0] : ii } end || [] issue = [issue] unless issue.is_a?(Array) issue.each do |i| nn << [i, i] end merged = nn.sort.each_with_object([]) do |(a, b), merged| if !merged.empty? && merged[-1][0] <= a && a <= merged[-1][1] + 1 merged[-1][1] = b if b > merged[-1][1] else merged << [a, b] end end Fbe.overwrite( f, 'issues', merged.map { |ii| ii[0] == ii[1] ? ii[0].to_s : "#{ii[0]}-#{ii[1]}" }, fb: @fb, fid: @fid ) end |
#has?(where, repo, issue) ⇒ Boolean
Is it there?
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fbe/tombstone.rb', line 88 def has?(where, repo, issue) raise(Fbe::Error, 'The type of "where" is not String') unless where.is_a?(String) raise(Fbe::Error, 'The type of "repo" is not Integer') unless repo.is_a?(Integer) unless issue.is_a?(Integer) || issue.is_a?(Array) raise(Fbe::Error, 'The type of "issue" is neither Integer nor Array') end f = @fb.query( "(and (eq where '#{where}') (eq what 'tombstone') (eq repository #{repo}) (exists issues))" ).each.first return false if f.nil? issue = [issue] unless issue.is_a?(Array) issue.all? do |i| f['issues'].any? do |ii| a, b = ii.split('-').map { |i| Integer(i, 10) } b.nil? ? a == i : (a..b).cover?(i) end end end |
#issues(where, repo) ⇒ Array<Integer>
See all issues in the tombstone, as array of numbers.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fbe/tombstone.rb', line 29 def issues(where, repo) raise(Fbe::Error, 'The type of "where" is not String') unless where.is_a?(String) raise(Fbe::Error, 'The type of "repo" is not Integer') unless repo.is_a?(Integer) f = @fb.query( "(and (eq where '#{where}') (eq what 'tombstone') (eq repository #{repo}) (exists issues))" ).each.first return [] if f.nil? f['issues'].flat_map do |ii| a, b = ii.split('-').map { |i| Integer(i, 10) } b = a if b.nil? (a..b).to_a end end |