fbe 0.0.76 → 0.0.77

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: c7d74bb1725292686a566e35d5de70e48ef024c5730238cd4ab70bc17376662d
4
- data.tar.gz: 94f38ca547e653eaae7f133ba8d61ee44db2ef31ea71bdcfccd39b12fe26571f
3
+ metadata.gz: 9ddebcf39a53a329190de82fa2ac0cd7396b3e2ba61f78a42071e2178a9b8d90
4
+ data.tar.gz: 05f078caf57e2b5f62454f01526c13b29f8e86988ed59d1f2c3edca46f2b60f3
5
5
  SHA512:
6
- metadata.gz: 418f6b9751ed8251fb8981b59f03957501b6ae0625dea457aecec2cb8913025e08ff45252c65b0ce896ea1c5774c244efeb5c309a2c2662738e5b9a6414a7592
7
- data.tar.gz: 143e8bf09239a7985a27d89907daa2b9bfb0b912f81d890e95343fcae960cc80997ae77a3203e0fe2fac2f551a56fbaffd10787f36e5607db457d147fa064cde
6
+ metadata.gz: 43aeba7ea29b28572827becf136f47c9dd6ed152c3469f94364acd68c389a9acb6cb55810317407e92a58d7a23dd0658f01662269ab1eb47c5749d9661096cb8
7
+ data.tar.gz: cf05b37c19c84c0414ab8eec86edc2fb700c371083dbdb67bbaf87cce8052db206c5bda8c5d119dc6b11b947da5ab89681da46901c779689a1a90997fa8304a5
data/Gemfile.lock CHANGED
@@ -2,21 +2,22 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  fbe (0.0.0)
5
- backtrace (> 0)
6
- decoor (> 0)
7
- factbase (> 0)
8
- faraday (> 0)
9
- faraday-http-cache (> 0)
10
- faraday-multipart (> 0)
11
- faraday-retry (> 0)
12
- graphql-client (> 0)
13
- judges (> 0)
5
+ backtrace (~> 0)
6
+ baza.rb (~> 0)
7
+ decoor (~> 0)
8
+ factbase (~> 0)
9
+ faraday (~> 2)
10
+ faraday-http-cache (~> 2)
11
+ faraday-multipart (~> 1)
12
+ faraday-retry (~> 2)
13
+ graphql-client (~> 0)
14
+ judges (~> 0)
14
15
  liquid (= 5.5.1)
15
- loog (> 0)
16
- obk (> 0)
17
- octokit (> 0)
18
- others (> 0)
19
- verbose (> 0)
16
+ loog (~> 0)
17
+ obk (~> 0)
18
+ octokit (~> 9)
19
+ others (~> 0)
20
+ verbose (~> 0)
20
21
 
21
22
  GEM
22
23
  remote: https://rubygems.org/
@@ -55,7 +56,7 @@ GEM
55
56
  ast (2.4.2)
56
57
  backtrace (0.4.0)
57
58
  base64 (0.2.0)
58
- baza.rb (0.0.8)
59
+ baza.rb (0.0.9)
59
60
  backtrace (> 0)
60
61
  elapsed (> 0)
61
62
  faraday (> 0)
@@ -112,7 +113,7 @@ GEM
112
113
  ffi (1.17.0-x86_64-linux-gnu)
113
114
  fiber-storage (1.0.0)
114
115
  gli (2.21.5)
115
- graphql (2.3.16)
116
+ graphql (2.3.18)
116
117
  base64
117
118
  fiber-storage
118
119
  graphql-client (0.23.0)
@@ -122,25 +123,25 @@ GEM
122
123
  i18n (1.14.6)
123
124
  concurrent-ruby (~> 1.0)
124
125
  io-console (0.7.2)
125
- irb (1.14.0)
126
+ irb (1.14.1)
126
127
  rdoc (>= 4.0.0)
127
128
  reline (>= 0.4.2)
128
129
  iri (0.8.0)
129
130
  json (2.7.2)
130
- judges (0.26.1)
131
- backtrace (> 0)
132
- baza.rb (> 0)
131
+ judges (0.27.0)
132
+ backtrace (~> 0)
133
+ baza.rb (~> 0)
133
134
  concurrent-ruby (~> 1.2)
134
- elapsed (> 0)
135
- factbase (> 0)
135
+ elapsed (~> 0)
136
+ factbase (~> 0)
136
137
  gli (~> 2.21)
137
- iri (> 0)
138
- loog (> 0)
138
+ iri (~> 0)
139
+ loog (~> 0)
139
140
  moments (~> 0.3)
140
141
  nokogiri (~> 1.10)
141
- others (> 0)
142
- retries (> 0)
143
- tago (> 0)
142
+ others (~> 0)
143
+ retries (~> 0)
144
+ tago (~> 0)
144
145
  typhoeus (~> 1.3)
145
146
  language_server-protocol (3.17.0.3)
146
147
  liquid (5.5.1)
@@ -180,7 +181,7 @@ GEM
180
181
  stringio
181
182
  public_suffix (6.0.1)
182
183
  racc (1.8.1)
183
- rack (3.1.7)
184
+ rack (3.1.8)
184
185
  rack-session (2.0.0)
185
186
  rack (>= 3.0.0)
186
187
  rack-test (2.1.0)
@@ -217,7 +218,7 @@ GEM
217
218
  rspec-expectations (3.13.3)
218
219
  diff-lcs (>= 1.2.0, < 2.0)
219
220
  rspec-support (~> 3.13.0)
220
- rspec-mocks (3.13.1)
221
+ rspec-mocks (3.13.2)
221
222
  diff-lcs (>= 1.2.0, < 2.0)
222
223
  rspec-support (~> 3.13.0)
223
224
  rspec-rails (7.0.1)
@@ -280,7 +281,7 @@ GEM
280
281
  webrick (1.8.2)
281
282
  yaml (0.3.0)
282
283
  yard (0.9.37)
283
- zeitwerk (2.6.18)
284
+ zeitwerk (2.7.0)
284
285
 
285
286
  PLATFORMS
286
287
  arm64-darwin-22
data/fbe.gemspec CHANGED
@@ -39,20 +39,21 @@ Gem::Specification.new do |s|
39
39
  s.files = `git ls-files`.split($RS)
40
40
  s.rdoc_options = ['--charset=UTF-8']
41
41
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
42
- s.add_dependency 'backtrace', '>0'
43
- s.add_dependency 'decoor', '>0'
44
- s.add_dependency 'factbase', '>0'
45
- s.add_dependency 'faraday', '>0'
46
- s.add_dependency 'faraday-http-cache', '>0'
47
- s.add_dependency 'faraday-multipart', '>0'
48
- s.add_dependency 'faraday-retry', '>0'
49
- s.add_dependency 'graphql-client', '>0'
50
- s.add_dependency 'judges', '>0'
42
+ s.add_dependency 'backtrace', '~>0'
43
+ s.add_dependency 'baza.rb', '~>0'
44
+ s.add_dependency 'decoor', '~>0'
45
+ s.add_dependency 'factbase', '~>0'
46
+ s.add_dependency 'faraday', '~>2'
47
+ s.add_dependency 'faraday-http-cache', '~>2'
48
+ s.add_dependency 'faraday-multipart', '~>1'
49
+ s.add_dependency 'faraday-retry', '~>2'
50
+ s.add_dependency 'graphql-client', '~>0'
51
+ s.add_dependency 'judges', '~>0'
51
52
  s.add_dependency 'liquid', '5.5.1'
52
- s.add_dependency 'loog', '>0'
53
- s.add_dependency 'obk', '>0'
54
- s.add_dependency 'octokit', '>0'
55
- s.add_dependency 'others', '>0'
56
- s.add_dependency 'verbose', '>0'
53
+ s.add_dependency 'loog', '~>0'
54
+ s.add_dependency 'obk', '~>0'
55
+ s.add_dependency 'octokit', '~>9'
56
+ s.add_dependency 'others', '~>0'
57
+ s.add_dependency 'verbose', '~>0'
57
58
  s.metadata['rubygems_mfa_required'] = 'true'
58
59
  end
data/lib/fbe/bylaws.rb CHANGED
@@ -25,17 +25,21 @@
25
25
  require 'liquid'
26
26
  require_relative '../fbe'
27
27
 
28
- # A generator of policies/bylaws.
28
+ # Generates policies/bylaws.
29
29
  #
30
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
32
- # License:: MIT
30
+ # Using the templates stored in the +assets/bylaws+ directory, this function
31
+ # creates a hash, where keys are names and values are formulas of bylaws.
32
+ #
33
+ # @param [Integer] anger How strict must be the bylaws, giving punishments
34
+ # @param [Integer] love How big should be the volume of rewards
35
+ # @param [Integer] paranoia How much should be required to reward love
36
+ # @return [Hash<String, String>] Names of bylaws and their formulas
33
37
  def Fbe.bylaws(anger: 2, love: 2, paranoia: 2)
34
- raise 'The "anger" must be in the [0..4] interval' unless !anger.negative? && anger < 5
35
- raise 'The "lover" must be in the [0..4] interval' unless !love.negative? && love < 5
36
- raise 'The "paranoia" must be in the [1..4] interval' unless paranoia.positive? && paranoia < 5
38
+ raise "The 'anger' must be in the [0..4] interval: #{anger.inspect}" unless !anger.negative? && anger < 5
39
+ raise "The 'love' must be in the [0..4] interval: #{love.inspect}" unless !love.negative? && love < 5
40
+ raise "The 'paranoia' must be in the [1..4] interval: #{paranoia.inspect}" unless paranoia.positive? && paranoia < 5
37
41
  home = File.join(__dir__, '../../assets/bylaws')
38
- raise "The directory with templates is absent '#{home}'" unless File.exist?(home)
42
+ raise "The directory with templates is absent #{home.inspect}" unless File.exist?(home)
39
43
  Dir[File.join(home, '*.liquid')].to_h do |f|
40
44
  formula = Liquid::Template.parse(File.read(f)).render(
41
45
  'anger' => anger, 'love' => love, 'paranoia' => paranoia
data/lib/fbe/conclude.rb CHANGED
@@ -27,19 +27,39 @@ require_relative 'fb'
27
27
  require_relative 'octo'
28
28
  require_relative 'if_absent'
29
29
 
30
- # Create a conclude code block.
30
+ # Creates an instance of {Fbe::Conclude} and evals it with the block provided.
31
31
  #
32
32
  # @param [Factbase] fb The factbase
33
33
  # @param [String] judge The name of the judge, from the +judges+ tool
34
34
  # @param [Hash] global The hash for global caching
35
35
  # @param [Judges::Options] options The options coming from the +judges+ tool
36
36
  # @param [Loog] loog The logging facility
37
+ # @yield [Factbase::Fact] The fact
37
38
  def Fbe.conclude(fb: Fbe.fb, judge: $judge, loog: $loog, options: $options, global: $global, &)
38
39
  c = Fbe::Conclude.new(fb:, judge:, loog:, options:, global:)
39
40
  c.instance_eval(&)
40
41
  end
41
42
 
42
- # Conclude.
43
+ # A concluding block.
44
+ #
45
+ # You may want to use this class when you want to go through a number
46
+ # of facts in the factbase, applying certain algorithm to each of them
47
+ # and possibly creating new facts from them.
48
+ #
49
+ # For example, you want to make a new +good+ fact for every +bad+ fact found:
50
+ #
51
+ # require 'fbe/conclude'
52
+ # conclude do
53
+ # on '(exist bad)'
54
+ # follow 'when'
55
+ # draw on |n, b|
56
+ # n.good = 'yes!'
57
+ # end
58
+ # end
59
+ #
60
+ # This snippet will find all facts that have +bad+ property and then create
61
+ # new facts, letting the block in the {Fbe::Conclude#draw} deal with them.
62
+ #
43
63
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
44
64
  # Copyright:: Copyright (c) 2024 Zerocracy
45
65
  # License:: MIT
@@ -62,19 +82,52 @@ class Fbe::Conclude
62
82
  @quota_aware = false
63
83
  end
64
84
 
85
+ # Make this block aware of GitHub API quota.
86
+ #
87
+ # When the quota is reached, the loop will gracefully stop.
88
+ #
89
+ # @return [nil] Nothing
65
90
  def quota_aware
66
91
  @quota_aware = true
67
92
  end
68
93
 
94
+ # Set the query that should find the facts in the factbase.
95
+ #
96
+ # @param [String] query The query
97
+ # @return [nil] Nothing
69
98
  def on(query)
70
99
  raise 'Query is already set' unless @query.nil?
71
100
  @query = query
72
101
  end
73
102
 
103
+ # Set the list of properties to copy from the facts found to new facts.
104
+ #
105
+ # @param [Arra<String>] props List of property names
106
+ # @return [nil] Nothing
74
107
  def follow(props)
75
- @follows = props.split
108
+ @follows = props.strip.split.compact
76
109
  end
77
110
 
111
+ # Create new fact from every fact found by the query.
112
+ #
113
+ # For example, you want to conclude a +reward+ from every +win+ fact:
114
+ #
115
+ # require 'fbe/conclude'
116
+ # conclude do
117
+ # on '(exist win)'
118
+ # follow 'win when'
119
+ # draw on |n, w|
120
+ # n.reward = 10
121
+ # end
122
+ # end
123
+ #
124
+ # This snippet will find all facts that have +win+ property and will create
125
+ # new facts for all of them, passing them one by one in to the block of
126
+ # the +draw+, where +n+ would be the new created fact and the +w+ would
127
+ # be the fact found.
128
+ #
129
+ # @yield [Array<Factbase::Fact,Factbase::Fact>] New fact and seen fact
130
+ # @return [Integer] The count of the facts processed
78
131
  def draw(&)
79
132
  roll do |fbt, a|
80
133
  n = fbt.insert
@@ -83,14 +136,20 @@ class Fbe::Conclude
83
136
  end
84
137
  end
85
138
 
86
- def maybe(&)
87
- roll do |fbt, a|
88
- Fbe.if_absent(fb: fbt) do |n|
89
- fill(n, a, &)
90
- end
91
- end
92
- end
93
-
139
+ # Take every fact, allowing the given block to process it.
140
+ #
141
+ # For example, you want to add +when+ property to every fact:
142
+ #
143
+ # require 'fbe/conclude'
144
+ # conclude do
145
+ # on '(always)'
146
+ # consider on |f|
147
+ # f.when = Time.new
148
+ # end
149
+ # end
150
+ #
151
+ # @yield [Factbase::Fact] The next fact found by the query
152
+ # @return [Integer] The count of the facts processed
94
153
  def consider(&)
95
154
  roll do |_fbt, a|
96
155
  yield a
@@ -100,6 +159,8 @@ class Fbe::Conclude
100
159
 
101
160
  private
102
161
 
162
+ # @yield [Factbase::Fact] The next fact found by the query
163
+ # @return [Integer] The count of the facts seen
103
164
  def roll(&)
104
165
  passed = 0
105
166
  catch :stop do
@@ -113,6 +174,7 @@ class Fbe::Conclude
113
174
  end
114
175
  end
115
176
  @loog.debug("Found and processed #{passed} facts by: #{@query}")
177
+ passed
116
178
  end
117
179
 
118
180
  def fill(fact, prev)
data/lib/fbe/copy.rb CHANGED
@@ -25,20 +25,27 @@
25
25
  require_relative '../fbe'
26
26
  require_relative 'fb'
27
27
 
28
- # Make a copy of a fact, moving all properties to a new fact.
28
+ # Makes a copy of a fact, moving all properties to a new fact.
29
+ #
30
+ # All properties from the +source+ will be copied to the +target+, except those
31
+ # listed in the +except+.
29
32
  #
30
33
  # @param [Factbase::Fact] source The source
31
34
  # @param [Factbase::Fact] target The targer
32
35
  # @param [Array<String>] except List of properties to NOT copy
36
+ # @return [Integer] How many properties were copied
33
37
  def Fbe.copy(source, target, except: [])
34
38
  raise 'The source is nil' if source.nil?
35
39
  raise 'The target is nil' if target.nil?
36
40
  raise 'The except is nil' if except.nil?
41
+ copied = 0
37
42
  source.all_properties.each do |k|
38
43
  next unless target[k].nil?
39
44
  next if except.include?(k)
40
45
  source[k].each do |v|
41
46
  target.send(:"#{k}=", v)
47
+ copied += 1
42
48
  end
43
49
  end
50
+ copied
44
51
  end
data/lib/fbe/enter.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MIT License
4
+ #
5
+ # Copyright (c) 2024 Zerocracy
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'baza-rb'
26
+ require_relative '../fbe'
27
+
28
+ # Enter a new valve.
29
+ #
30
+ # @param [String] badge Unique badge of the valve
31
+ # @param [String] why The reason
32
+ # @param [Judges::Options] options The options coming from the +judges+ tool
33
+ # @param [Loog] loog The logging facility
34
+ # @return [String] Full name of the user
35
+ def Fbe.enter(badge, why, options: $options, loog: $loog, &)
36
+ baza = BazaRb.new('api.zerocracy.com', 443, options.zerocracy_token, loog:)
37
+ baza.enter(options.job_name, badge, why, options.job_id.to_i, &)
38
+ end
data/lib/fbe/fb.rb CHANGED
@@ -32,10 +32,15 @@ require_relative '../fbe'
32
32
 
33
33
  # Returns an instance of +Factbase+ (cached).
34
34
  #
35
+ # Instead of using +$fb+ directly, it is recommended to use this utility
36
+ # method. It will not only return the global factbase, but will also
37
+ # make sure it's properly decorated and cached.
38
+ #
35
39
  # @param [Factbase] fb The global factbase provided by the +judges+ tool
36
40
  # @param [Hash] global The hash for global caching
37
41
  # @param [Judges::Options] options The options coming from the +judges+ tool
38
42
  # @param [Loog] loog The logging facility
43
+ # @return [Factbase] The global factbase
39
44
  def Fbe.fb(fb: $fb, global: $global, options: $options, loog: $loog)
40
45
  global[:fb] ||=
41
46
  begin
@@ -22,15 +22,16 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  # SOFTWARE.
24
24
 
25
- require 'loog'
26
25
  require 'graphql/client'
27
26
  require 'graphql/client/http'
27
+ require 'loog'
28
28
 
29
- # Interface to GitHub GraphQL API.
29
+ # Creates an instance of {Fbe::Graph}.
30
30
  #
31
31
  # @param [Judges::Options] options The options available globally
32
32
  # @param [Hash] global Hash of global options
33
33
  # @param [Loog] loog Logging facility
34
+ # @return [Fbe::Graph] The instance of the class
34
35
  def Fbe.github_graph(options: $options, global: $global, loog: $loog)
35
36
  global[:github_graph] ||=
36
37
  if options.testing.nil?
@@ -41,7 +42,11 @@ def Fbe.github_graph(options: $options, global: $global, loog: $loog)
41
42
  end
42
43
  end
43
44
 
44
- # The GitHub GraphQL client
45
+ # A client to GitHub GraphQL.
46
+ #
47
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
48
+ # Copyright:: Copyright (c) 2024 Zerocracy
49
+ # License:: MIT
45
50
  class Fbe::Graph
46
51
  def initialize(token:, host: 'api.github.com')
47
52
  @token = token
data/lib/fbe/if_absent.rb CHANGED
@@ -22,13 +22,33 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  # SOFTWARE.
24
24
 
25
- require 'time'
26
25
  require 'others'
26
+ require 'time'
27
27
  require_relative '../fbe'
28
28
  require_relative 'fb'
29
29
 
30
30
  # Injects a fact if it's absent in the factbase, otherwise (it is already
31
31
  # there) returns NIL.
32
+ #
33
+ # Here is what you do when you want to add a fact to the factbase, but
34
+ # don't want to make a duplicate of an existing one:
35
+ #
36
+ # require 'fbe/if_absent'
37
+ # n =
38
+ # Fbe.if_absent do |f|
39
+ # f.what = 'something'
40
+ # f.details = 'important'
41
+ # end
42
+ # return if n.nil?
43
+ # n.when = Time.now
44
+ #
45
+ # This code will definitely create one fact with +what+ equals to +something+
46
+ # and +details+ equals to +important+, while the +when+ will be equal to the
47
+ # time of its first creation.
48
+ #
49
+ # @param [Factbase] fb The global factbase
50
+ # @yield [Factbase::Fact] The fact just created
51
+ # @return [nil|Factbase::Fact] Either +nil+ if it's already there or a new fact
32
52
  def Fbe.if_absent(fb: Fbe.fb)
33
53
  attrs = {}
34
54
  f =
@@ -51,7 +71,8 @@ def Fbe.if_absent(fb: Fbe.fb)
51
71
  "(eq #{k} #{vv})"
52
72
  end.join(' ')
53
73
  q = "(and #{q})"
54
- return nil unless fb.query(q).each.to_a.empty?
74
+ before = fb.query(q).each.to_a.first
75
+ return nil if before
55
76
  n = fb.insert
56
77
  attrs.each { |k, v| n.send("#{k}=", v) }
57
78
  n
data/lib/fbe/issue.rb CHANGED
@@ -23,13 +23,20 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require_relative '../fbe'
26
+ require_relative 'octo'
26
27
 
27
28
  # Converts an ID of GitHub issue into a nicely formatting string.
28
29
  #
30
+ # The function takes the +repository+ property of the provided +fact+,
31
+ # goes to the GitHub API in order to find the full name of the repository,
32
+ # and then creates a string with the full name of repository + issue, for
33
+ # example +"zerocracy/fbe#42"+.
34
+ #
29
35
  # @param [Factbase::Fact] fact The fact, where to get the ID of GitHub issue
30
36
  # @param [Judges::Options] options The options coming from the +judges+ tool
31
37
  # @param [Hash] global The hash for global caching
32
38
  # @param [Loog] loog The logging facility
39
+ # @return [String] Textual representation of GitHub issue number
33
40
  def Fbe.issue(fact, options: $options, global: $global, loog: $loog)
34
41
  rid = fact['repository']
35
42
  raise "There is no 'repository' property" if rid.nil?
data/lib/fbe/iterate.rb CHANGED
@@ -23,21 +23,40 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require_relative '../fbe'
26
- require_relative 'unmask_repos'
27
- require_relative 'octo'
28
26
  require_relative 'fb'
27
+ require_relative 'octo'
28
+ require_relative 'unmask_repos'
29
29
 
30
- # Create a conclude code block.
30
+ # Creates an instance of {Fbe::Iterate} and evals it with the block provided.
31
+ #
32
+ # @param [Factbase] fb The global factbase provided by the +judges+ tool
33
+ # @param [Judges::Options] options The options coming from the +judges+ tool
34
+ # @param [Hash] global The hash for global caching
35
+ # @param [Loog] loog The logging facility
36
+ # @yield [Factbase::Fact] The fact
31
37
  def Fbe.iterate(fb: Fbe.fb, loog: $loog, options: $options, global: $global, &)
32
38
  c = Fbe::Iterate.new(fb:, loog:, options:, global:)
33
39
  c.instance_eval(&)
34
40
  end
35
41
 
36
- # Iterate.
42
+ # An iterator.
43
+ #
44
+ # Here, you go through all repositories defined by the +repositories+ option
45
+ # in the +$options+, trying to run the provided query for each of them. If the
46
+ # query returns an integer that is different from the previously seen, the
47
+ # function keeps repeating the cycle. Otherwise, it will restart from the
48
+ # beginning.
49
+ #
37
50
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
38
51
  # Copyright:: Copyright (c) 2024 Zerocracy
39
52
  # License:: MIT
40
53
  class Fbe::Iterate
54
+ # Ctor.
55
+ #
56
+ # @param [Factbase] fb The factbase
57
+ # @param [Loog] loog The logging facility
58
+ # @param [Judges::Options] options The options coming from the +judges+ tool
59
+ # @param [Hash] global The hash for global caching
41
60
  def initialize(fb:, loog:, options:, global:)
42
61
  @fb = fb
43
62
  @loog = loog
@@ -50,22 +69,39 @@ class Fbe::Iterate
50
69
  @quota_aware = false
51
70
  end
52
71
 
72
+ # Make this block aware of GitHub API quota.
73
+ #
74
+ # When the quota is reached, the loop will gracefully stop.
75
+ #
76
+ # @return [nil] Nothing
53
77
  def quota_aware
54
78
  @quota_aware = true
55
79
  end
56
80
 
81
+ # Sets the total counter of repeats to make.
82
+ #
83
+ # @param [Integer] repeats The total count of them
84
+ # @return [nil] Nothing
57
85
  def repeats(repeats)
58
86
  raise 'Cannot set "repeats" to nil' if repeats.nil?
59
87
  raise 'The "repeats" must be a positive integer' unless repeats.positive?
60
88
  @repeats = repeats
61
89
  end
62
90
 
91
+ # Sets the query to run.
92
+ #
93
+ # @param [String] query The query
94
+ # @return [nil] Nothing
63
95
  def by(query)
64
96
  raise 'Query is already set' unless @query.nil?
65
97
  raise 'Cannot set query to nil' if query.nil?
66
98
  @query = query
67
99
  end
68
100
 
101
+ # Sets the label to use in the "marker" fact.
102
+ #
103
+ # @param [String] label The label
104
+ # @return [nil] Nothing
69
105
  def as(label)
70
106
  raise 'Label is already set' unless @label.nil?
71
107
  raise 'Cannot set "label" to nil' if label.nil?
@@ -73,10 +109,13 @@ class Fbe::Iterate
73
109
  end
74
110
 
75
111
  # It makes a number of repeats of going through all repositories
76
- # provided by the "repositories" configuration option. In each "repeat"
112
+ # provided by the +repositories+ configuration option. In each "repeat"
77
113
  # it yields the repository ID and a number that is retrieved by the
78
- # "query". The query is supplied with two parameter:
79
- # "$before" (the value from the previous repeat and "$rid" (the repo ID).
114
+ # +query+. The query is supplied with two parameter:
115
+ # +$before+ the value from the previous repeat and +$repository+ (GitHub repo ID).
116
+ #
117
+ # @yield [Array<Integer, Integer>] Repository ID and the next number to be considered
118
+ # @return [nil] Nothing
80
119
  def over(&)
81
120
  raise 'Use "as" first' if @label.nil?
82
121
  raise 'Use "by" first' if @query.nil?
data/lib/fbe/just_one.rb CHANGED
@@ -29,6 +29,20 @@ require_relative 'fb'
29
29
 
30
30
  # Injects a fact if it's absent in the factbase, otherwise (it is already
31
31
  # there) returns the existing one.
32
+ #
33
+ # require 'fbe/just_one'
34
+ # n =
35
+ # Fbe.just_one do |f|
36
+ # f.what = 'something'
37
+ # f.details = 'important'
38
+ # end
39
+ #
40
+ # This code will guarantee that only one fact with +what+ equals to +something+
41
+ # and +details+ equals to +important+ may exist.
42
+ #
43
+ # @param [Factbase] fb The global factbase
44
+ # @yield [Factbase::Fact] The fact that was either created or found
45
+ # @return [Factbase::Fact] The fact found
32
46
  def Fbe.just_one(fb: Fbe.fb)
33
47
  attrs = {}
34
48
  f =
@@ -25,6 +25,10 @@
25
25
  require 'faraday'
26
26
 
27
27
  # Faraday Middleware that monitors GitHub API rate limits.
28
+ #
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Zerocracy
31
+ # License:: MIT
28
32
  class Fbe::Middleware::Quota < Faraday::Middleware
29
33
  def initialize(app, loog: Loog::NULL, pause: 60, limit: 100, rate: 5)
30
34
  super(app)
@@ -25,6 +25,10 @@
25
25
  require_relative '../fbe'
26
26
 
27
27
  # The module.
28
+ #
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Zerocracy
31
+ # License:: MIT
28
32
  module Fbe::Middleware
29
33
  # empty
30
34
  end