fbe 0.0.42 → 0.0.43

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: '095a45978ce9e57eae04c5d10dc974071b3400dfe5f3fe0ce5da88acf87d6fd1'
4
- data.tar.gz: 63e430609dab7392f310b9772f35a427d8ec8799717da1a7fb70c4552d92a44c
3
+ metadata.gz: '081da62424351c5ee65fc8a949e74f16326905f3a0748d89ba47d13ee2a5e5df'
4
+ data.tar.gz: fd71a1f8d8fd721c992a46f16269357c7e784aac172b1909f09e97436190d971
5
5
  SHA512:
6
- metadata.gz: 223d399f84eb5a6290b4c0e13d0e04124a6ebd449964ce60b439942b73e6fda71db43ddead097b0a8ca15adea0e37bf9e6d5938a281d602ba3333fd4634bcdda
7
- data.tar.gz: 405c244aa9637bda9fb035051248c54edf9c6eba6008f4c371e435a34ab5e80c7d93b4796e55650335714b30062cbf66b211acb7bdf48a8270fbeb5fd0c29ae7
6
+ metadata.gz: 5752ff7c46fba04d57d6357209827994c45d693d9447a951ba6118dd56d9d2b96774bd141316ae9d17e1552ba98476be7ef1b8edb70538cf43ac6d80887b7e97
7
+ data.tar.gz: 0a8a030cfd4781ef70841db89a6e4db6114e83083ae111e5d80fc51093795ba1251f400b5cb0cf795db3f15baef105079101d74213d68637801127e15cda912e
@@ -26,13 +26,20 @@ require 'faraday'
26
26
 
27
27
  # Faraday Middleware that monitors GitHub API rate limits.
28
28
  class Fbe::Middleware::Quota < Faraday::Middleware
29
- def initialize(app, logger: Loog::NULL, pause: 60, limit: 100, rate: 5)
29
+ def initialize(app, loog: Loog::NULL, pause: 60, limit: 100, rate: 5)
30
30
  super(app)
31
- @limit = limit
32
31
  @requests = 0
33
32
  @app = app
34
- @logger = logger
33
+ raise 'The "loog" cannot be nil' if loog.nil?
34
+ @loog = loog
35
+ raise 'The "pause" cannot be nil' if pause.nil?
36
+ raise 'The "pause" must be a positive integer' unless pause.positive?
35
37
  @pause = pause
38
+ raise 'The "limit" cannot be nil' if limit.nil?
39
+ raise 'The "limit" must be a positive integer' unless limit.positive?
40
+ @limit = limit
41
+ raise 'The "rate" cannot be nil' if rate.nil?
42
+ raise 'The "rate" must be a positive integer' unless rate.positive?
36
43
  @rate = rate
37
44
  end
38
45
 
@@ -40,7 +47,7 @@ class Fbe::Middleware::Quota < Faraday::Middleware
40
47
  @requests += 1
41
48
  response = @app.call(env)
42
49
  if out_of_limit?(env)
43
- @logger.info(
50
+ @loog.info(
44
51
  "Too much GitHub API quota consumed, pausing for #{@pause} seconds"
45
52
  )
46
53
  sleep(@pause)
data/lib/fbe/octo.rb CHANGED
@@ -33,6 +33,15 @@ require_relative '../fbe'
33
33
  require_relative 'middleware'
34
34
  require_relative 'middleware/quota'
35
35
 
36
+ # Interface to GitHub API.
37
+ #
38
+ # It is supposed to be used instead of Octokit client, because it
39
+ # is pre-configured and enables additional fearues, such as retrying,
40
+ # logging, and caching.
41
+ #
42
+ # @param [Judges::Options] options The options available globally
43
+ # @param [Hash] global Hash of global options
44
+ # @param [Loog] loog Logging facility
36
45
  def Fbe.octo(options: $options, global: $global, loog: $loog)
37
46
  raise 'The $global is not set' if global.nil?
38
47
  global[:octo] ||=
@@ -79,11 +88,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
79
88
  methods: [:get],
80
89
  backoff_factor: 2
81
90
  )
82
- builder.use(
83
- Fbe::Middleware::Quota,
84
- logger: loog,
85
- pause: options.github_api_pause
86
- )
91
+ builder.use(Fbe::Middleware::Quota, loog:, pause: options.github_api_pause || 60)
87
92
  builder.use(Faraday::HttpCache, serializer: Marshal, shared_cache: false, logger: Loog::NULL)
88
93
  builder.use(Octokit::Response::RaiseError)
89
94
  builder.use(Faraday::Response::Logger, Loog::NULL)
data/lib/fbe/overwrite.rb CHANGED
@@ -38,11 +38,12 @@ require_relative 'fb'
38
38
  # @param [String] property The name of the property to set
39
39
  # @param [Any] vqlue The value to set
40
40
  def Fbe.overwrite(fact, property, value, fb: Fbe.fb)
41
+ raise 'The fact is nil' if fact.nil?
41
42
  before = {}
42
43
  fact.all_properties.each do |prop|
43
44
  before[prop.to_s] = fact[prop]
44
45
  end
45
- id = fact['_id'].first
46
+ id = fact['_id']&.first
46
47
  raise 'There is no _id in the fact, cannot use Fbe.overwrite' if id.nil?
47
48
  raise "No facts by _id = #{id}" if fb.query("(eq _id #{id})").delete!.zero?
48
49
  n = fb.insert
data/lib/fbe.rb CHANGED
@@ -27,5 +27,5 @@
27
27
  # License:: MIT
28
28
  module Fbe
29
29
  # Current version of the gem (changed by .rultor.yml on every release)
30
- VERSION = '0.0.42'
30
+ VERSION = '0.0.43'
31
31
  end
@@ -45,9 +45,9 @@ class QuotaTest < Minitest::Test
45
45
 
46
46
  def test_quota_middleware_pauses_when_quota_low
47
47
  loog = Loog::NULL
48
- pause = 0
48
+ pause = 1
49
49
  app = FakeApp.new
50
- middleware = Fbe::Middleware::Quota.new(app, logger: loog, pause:)
50
+ middleware = Fbe::Middleware::Quota.new(app, loog:, pause:)
51
51
  start_time = Time.now
52
52
  105.times do
53
53
  env = Judges::Options.new(
@@ -66,7 +66,7 @@ class QuotaTest < Minitest::Test
66
66
  log_output = StringIO.new
67
67
  loog = Logger.new(log_output)
68
68
  app = FakeApp.new
69
- middleware = Fbe::Middleware::Quota.new(app, logger: loog, pause:)
69
+ middleware = Fbe::Middleware::Quota.new(app, loog:, pause:)
70
70
  105.times do
71
71
  env = Judges::Options.new(
72
72
  'method' => :get,
@@ -54,6 +54,14 @@ class TestOverwrite < Minitest::Test
54
54
  assert_equal(42, fb.query('(always)').each.to_a.first['foo'].first)
55
55
  end
56
56
 
57
+ def test_without_id
58
+ fb = Factbase.new
59
+ f = fb.insert
60
+ assert_raises do
61
+ Fbe.overwrite(f, :foo, 42, fb:)
62
+ end
63
+ end
64
+
57
65
  def test_safe_insert
58
66
  fb = Factbase.new
59
67
  f1 = fb.insert
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.42
4
+ version: 0.0.43
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-08-07 00:00:00.000000000 Z
11
+ date: 2024-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace