ruby_rate_limiter 2.0.6 → 2.0.8

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: 2b91aa072c7328841e3dcc45fc7588228e15628759e214edf01f44d734dc29f5
4
- data.tar.gz: 2d3bbefb032d976e9fe04274faf77df7b8ba8a666f8a9698ec559d597e391a89
3
+ metadata.gz: f812a1ae8b8449217f489de3234d4f26a077bdc4f8bd6653dbe29457c363ab23
4
+ data.tar.gz: f2941667395af0a013e11c87394ab355ed5c01ec789fdc294e5eb84ef4ac4c3b
5
5
  SHA512:
6
- metadata.gz: 7cbffc4b009083f739d258ce49be8bde4f557555ae5f5ae088c170e15bef519c9cfbb783feb675193b4c42903717d2cd4d0cd155138bf8949762e3d270124459
7
- data.tar.gz: 765cbaf643f826267513176e0624e7f064d09eaed54ce504185de17a023bef80f5744b0f5f4fbf3bf3e031e634ec731665f421f7c043eaf882f280625a402554
6
+ metadata.gz: ebd5d104e4172e0b32856dc26b815b04d0a49b89b35e7a9c8520ad474ab00e2dfb5c2771078a579e8c9075b49ed84a75c2b98e5e5ad672ec4b750ef576ea1eaf
7
+ data.tar.gz: e402b83a46be87121443283dc178a8eabed68056c44a23423f2c008d0bc5f9c7d8f5a870fb1c00ef629f5ad006501c42267fbb4ae01532030f434409662b8d1c
@@ -47,9 +47,10 @@ module RubyRateLimiter
47
47
  private
48
48
 
49
49
  def initialize_bucket
50
- if get_bucket_size.nil?
50
+ if @storage.get("#{@user_id}_tokens").nil?
51
51
  update_bucket_size(@bucket_size)
52
52
  update_last_refill_time(Time.now.to_f)
53
+ puts "Initialized bucket: tokens = #{@bucket_size}, time = #{Time.now.to_f}"
53
54
  end
54
55
  end
55
56
 
@@ -77,15 +78,21 @@ module RubyRateLimiter
77
78
  current_time = Time.now.to_f
78
79
  last_refill_time = get_last_refill_time
79
80
  elapsed_time = current_time - last_refill_time
81
+
82
+ if elapsed_time < 0
83
+ puts "Warning: elapsed_time is negative. Adjusting to zero."
84
+ elapsed_time = 0
85
+ end
86
+
80
87
  new_tokens = (elapsed_time * @refill_rate_per_second).to_i
81
88
  puts "Refill tokens: current_time = #{current_time}, last_refill_time = #{last_refill_time}, elapsed_time = #{elapsed_time}, new_tokens = #{new_tokens}" # Debugging line
82
-
83
- return if new_tokens <= 0
84
-
85
- tokens = [get_bucket_size + new_tokens, @bucket_size].min
86
- update_bucket_size(tokens)
87
- update_last_refill_time(current_time)
88
- puts "Refill tokens: updated tokens = #{tokens}, current_time = #{current_time}" # Debugging line
89
+
90
+ if new_tokens > 0
91
+ tokens = [get_bucket_size + new_tokens, @bucket_size].min
92
+ update_bucket_size(tokens)
93
+ update_last_refill_time(current_time)
94
+ puts "Refill tokens: updated tokens = #{tokens}, current_time = #{current_time}" # Debugging line
95
+ end
89
96
  end
90
97
  end
91
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RateLimiter
4
- VERSION = "2.0.6"
4
+ VERSION = "2.0.8"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_rate_limiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mutuba