co-limit 0.1.1 → 0.1.2
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 +4 -4
- data/lib/limit/version.rb +1 -1
- data/lib/limit.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f54e6c9ae0b841090b1fe2eae972242c4a416eb504de4940cc807a500f7d27a
|
4
|
+
data.tar.gz: ebc7e45c7c29b425a4391230173f8db3a44c288482a917f2ef8e57be75552a31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8535547535b239b227de6f78dfa0c37380e33c77f74db7c85ad91792068847b44f9074b02b3e034f9d94c8c89d517ac884ab18f111aaaca8bdeee02fc774b2ba
|
7
|
+
data.tar.gz: b37ee6f384eed0728a8b4a29b3271475bbe42607c0d879471081947ec4d2c34ef7d14be28f95b305094cf2cb8c548c6aa3a5a1b77fdc5fbf0eac52711fe0ac53
|
data/lib/limit/version.rb
CHANGED
data/lib/limit.rb
CHANGED
@@ -43,8 +43,8 @@ module Limit
|
|
43
43
|
|
44
44
|
def initialize(identifier_prefix:, limit_calculator:, host: nil, port: nil, password: nil)
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# @param identifier_prefix: [String] A namespace prefix for redis keys for this limiter instance
|
47
|
+
# @param limit_calculator: [Lambda] A method that takes a key(String) and returns hash: {max_requests: Integer, window_seconds: Integer}
|
48
48
|
|
49
49
|
unless identifier_prefix.is_a?(String) && !identifier_prefix.empty?
|
50
50
|
raise ArgumentError, 'identifier_prefix must be a non-empty String'
|
@@ -78,7 +78,7 @@ module Limit
|
|
78
78
|
raise NotImplementedError "#{self.class.name} must implement the allowed? method"
|
79
79
|
end
|
80
80
|
|
81
|
-
def get_key(
|
81
|
+
def get_key(key)
|
82
82
|
raise NotImplementedError "#{self.class.name} must implement the get_key() method"
|
83
83
|
end
|
84
84
|
|
@@ -136,9 +136,9 @@ module Limit
|
|
136
136
|
results[0] <= max_requests
|
137
137
|
end
|
138
138
|
|
139
|
-
def get_key(
|
139
|
+
def get_key(key, window_seconds)
|
140
140
|
time_window = (Time.now.to_i / window_seconds) * window_seconds
|
141
|
-
"#{@identifier_prefix}:#{
|
141
|
+
"#{@identifier_prefix}:#{key}:#{time_window.to_s}"
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -167,8 +167,8 @@ module Limit
|
|
167
167
|
results[2] <= max_requests
|
168
168
|
end
|
169
169
|
|
170
|
-
def get_key(
|
171
|
-
"#{@identifier_prefix}:#{
|
170
|
+
def get_key(key)
|
171
|
+
"#{@identifier_prefix}:#{key}"
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: co-limit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CosmicOppai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|