fbe 0.21.2 → 0.22.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: f6593e4483941c4ff99de6f85aab33f62832d4293b1efb2a8e84d0b78ad79147
4
- data.tar.gz: 134ceee60e4eb50c33b8c71194ffa0464c822e07884bd230776e5c59f025e2f7
3
+ metadata.gz: e5a39208fa372c54abc221588d0a96f234cfd7ba3c56a65fa1c9d71a5eb119e9
4
+ data.tar.gz: 97ef98fd304ce75ec5558a8915d3a8f95482cf0d203d3ede0882021b7bc036ea
5
5
  SHA512:
6
- metadata.gz: a43a4fb0ef720d9e459d348437c7d3824625fae9aad064c768885fc945d25e0ba68b0034132c97dd0835bf93edbcd960d64d4aa9f9bbd31af5c5589f2121ef44
7
- data.tar.gz: 5f76047d167636f220b5bcab707b2f69bbe47a471b5954a4dbe324055fb08556cec5470ac7d1d9bb22da436b91d69056b5205bf485b4ca3b63ea212eb0f649ad
6
+ metadata.gz: e17fbbbc95d55c4e0a9ec6611ba5ab1fcee8e42fb9e126a3d46bdb3e20bbad7d0c140d58f519275f71ce11d4a2d6399a211868638e208324b42dc5e577a988e1
7
+ data.tar.gz: d1fac9af3a2e773f23ad7a9392499feb01af4b7786654cf2fdb7140744e2fec4386d5ce45b49ea37432a9f31b9d9ca97fcec3b7c8be5b638b833ce6215b898f0
data/Gemfile.lock CHANGED
@@ -180,7 +180,7 @@ GEM
180
180
  regexp_parser (2.10.0)
181
181
  retries (0.0.5)
182
182
  rexml (3.4.1)
183
- rubocop (1.76.2)
183
+ rubocop (1.77.0)
184
184
  json (~> 2.3)
185
185
  language_server-protocol (~> 3.17.0.2)
186
186
  lint_roller (~> 1.1.0)
data/fbe.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  'manipulate the facts and create new ones'
19
19
  s.authors = ['Yegor Bugayenko']
20
20
  s.email = 'yegor256@gmail.com'
21
- s.homepage = 'http://github.com/zerocracy/fbe'
21
+ s.homepage = 'https://github.com/zerocracy/fbe'
22
22
  s.files = `git ls-files`.split($RS)
23
23
  s.rdoc_options = ['--charset=UTF-8']
24
24
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
@@ -51,8 +51,9 @@ class Fbe::Middleware::SqliteStore
51
51
  # @param version [String] Version identifier for cache compatibility
52
52
  # @param loog [Loog] Logger instance (optional, defaults to Loog::NULL)
53
53
  # @param maxsize [Integer] Maximum database size in bytes (optional, defaults to 10MB)
54
+ # @param maxvsize [Integer] Maximum size in bytes of a single value (optional, defaults to 10Kb)
54
55
  # @raise [ArgumentError] If path is nil/empty, directory doesn't exist, or version is nil/empty
55
- def initialize(path, version, loog: Loog::NULL, maxsize: 10 * 1024 * 1024)
56
+ def initialize(path, version, loog: Loog::NULL, maxsize: 10 * 1024 * 1024, maxvsize: 10 * 1024)
56
57
  raise ArgumentError, 'Database path cannot be nil or empty' if path.nil? || path.empty?
57
58
  dir = File.dirname(path)
58
59
  raise ArgumentError, "Directory #{dir} does not exist" unless File.directory?(dir)
@@ -61,6 +62,7 @@ class Fbe::Middleware::SqliteStore
61
62
  @version = version
62
63
  @loog = loog
63
64
  @maxsize = maxsize
65
+ @maxvsize = maxvsize
64
66
  end
65
67
 
66
68
  # Read a value from the cache.
@@ -91,10 +93,10 @@ class Fbe::Middleware::SqliteStore
91
93
  def write(key, value)
92
94
  return if value.is_a?(Array) && value.any? do |vv|
93
95
  req = JSON.parse(vv[0])
94
- req['url'].include?('?') || req['method'] != 'get'
96
+ req['method'] != 'get'
95
97
  end
96
98
  value = JSON.dump(value)
97
- return if value.bytesize > 10_000
99
+ return if value.bytesize > @maxvsize
98
100
  perform do |t|
99
101
  t.execute(<<~SQL, [key, value, Time.now.utc.iso8601])
100
102
  INSERT INTO cache(key, value, touched_at) VALUES(?1, ?2, ?3)
data/lib/fbe/octo.rb CHANGED
@@ -83,7 +83,8 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
83
83
  )
84
84
  if options.sqlite_cache
85
85
  maxsize = options.sqlite_cache_maxsize || (10 * 1024 * 1024)
86
- store = Fbe::Middleware::SqliteStore.new(options.sqlite_cache, Fbe::VERSION, loog:, maxsize:)
86
+ maxvsize = options.sqlite_cache_maxxsize || (10 * 1024)
87
+ store = Fbe::Middleware::SqliteStore.new(options.sqlite_cache, Fbe::VERSION, loog:, maxsize:, maxvsize:)
87
88
  loog.info(
88
89
  "Using HTTP cache in SQLite file: #{store.path} (" \
89
90
  "#{File.exist?(store.path) ? "#{File.size(store.path)} bytes" : 'file is absent'}, " \
@@ -176,7 +177,9 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
176
177
  end
177
178
  o =
178
179
  others(o:) do |*args|
179
- raise "We are off-quota (remaining: #{@o.rate_limit.remaining})" if args.first != :off_quota? && @o.off_quota?
180
+ if args.first != :off_quota? && args.first != :print_trace! && @o.off_quota?
181
+ raise "We are off-quota (remaining: #{@o.rate_limit.remaining})"
182
+ end
180
183
  @o.__send__(*args)
181
184
  end
182
185
  o
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.21.2' unless const_defined?(:VERSION)
13
+ VERSION = '0.22.0' unless const_defined?(:VERSION)
14
14
  end
@@ -143,8 +143,8 @@ class SqliteStoreTest < Fbe::Test
143
143
  Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
144
144
  store.write('a', 'a' * 9_997)
145
145
  store.write('b', 'b' * 9_998)
146
- store.write('c', 'c' * 9_999)
147
- store.write('d', 'd' * 10_000)
146
+ store.write('c', 'c' * 19_999)
147
+ store.write('d', 'd' * 30_000)
148
148
  assert_equal('a' * 9_997, store.read('a'))
149
149
  assert_equal('b' * 9_998, store.read('b'))
150
150
  assert_nil(store.read('c'))
@@ -56,8 +56,7 @@ class TestOcto < Fbe::Test
56
56
  stub_request(:get, 'https://api.github.com/rate_limit').to_return(
57
57
  { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
58
58
  )
59
- global = {}
60
- o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
59
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
61
60
  stub_request(:get, 'https://api.github.com/user/42').to_return(
62
61
  body: { login: 'Dude56' }.to_json, headers: { 'Content-Type': 'application/json' }
63
62
  )
@@ -65,6 +64,24 @@ class TestOcto < Fbe::Test
65
64
  assert_equal('dude56', nick)
66
65
  end
67
66
 
67
+ def test_fails_user_request_when_off_quota
68
+ WebMock.disable_net_connect!
69
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
70
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '3' } }
71
+ )
72
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
73
+ assert_raises(StandardError) { o.user(42) }
74
+ end
75
+
76
+ def test_no_failure_on_printing_when_off_quota
77
+ WebMock.disable_net_connect!
78
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
79
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '3' } }
80
+ )
81
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
82
+ o.print_trace!
83
+ end
84
+
68
85
  def test_reads_repo_name_by_id
69
86
  WebMock.disable_net_connect!
70
87
  stub_request(:get, 'https://api.github.com/rate_limit').to_return(
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.21.2
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -358,7 +358,7 @@ files:
358
358
  - test/fbe/test_who.rb
359
359
  - test/test__helper.rb
360
360
  - test/test_fbe.rb
361
- homepage: http://github.com/zerocracy/fbe
361
+ homepage: https://github.com/zerocracy/fbe
362
362
  licenses:
363
363
  - MIT
364
364
  metadata: