co-limit 0.1.0 → 0.1.1

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: 72909f9bdd98c89548d9513f2431095a7edf110f0b2b62a3f928cb5f2f65ddba
4
- data.tar.gz: a9be065e44bedb462c7595cf35bbb2a7f1feb9097f97581e210130891089d21e
3
+ metadata.gz: 4686cb64b1936e1c6c1420557f947a27263f498f7f0f1f90074e79a27dd400b8
4
+ data.tar.gz: 7373d4fb997a7d3d2293525e1e8096e21bfb70b3b92ad5f91917467883561ebf
5
5
  SHA512:
6
- metadata.gz: 20aee9b9a5a274424f880119f9dd7c59eb82624ceef1d3194e0c527b1a029370628563bb22885d5b688210504a02b244a744f60d2565825f7ad1970ac5e1f8ee
7
- data.tar.gz: 3992bd40ac746931e6a797e0838cc36318029ca394cb425d84598636597761a461964857ce6ad35dc21ae79be8e434522758a7f2eb7ec1974a17c74447f51b1e
6
+ metadata.gz: d2bc5af6b8acd79aa457d872302f597f55479d324390b1267a3e35c8d3e8469621851dc995f243b3aa6847c5c6bcb5d7787a8d2b93e95c3eca6738f52f7bc19e
7
+ data.tar.gz: 55ce9a1e9e90dff76b8e56aac61a65e736c1e77bf6d519ebc7f85fdf6c0d3b7d6eaa98107f9719aaf7be3d978af79958ba0ae3eb07d3f448a5c7fd4363a47904
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem that provides flexible, Redis-backed rate limiting utilities. It supports both Fixed Window and Rolling Window (Sliding Log) strategies, to easily control the number of allowed requests for a given identifier within a time window.
5
5
 
6
- You can define rate-limiting rules dynamically using a Proc, and configure Redis via environment variables (REDIS_HOST, REDIS_PORT, REDIS_PASSWORD) or by passing connection details directly.
6
+ You can define rate-limiting rules dynamically using a lambda, and configure Redis via environment variables (REDIS_HOST, REDIS_PORT, REDIS_PASSWORD) or by passing connection details directly.
7
7
 
8
8
  This gem is ideal for APIs, background jobs, or any system that needs simple, efficient throttling logic.
9
9
 
@@ -12,13 +12,13 @@ This gem is ideal for APIs, background jobs, or any system that needs simple, ef
12
12
  To install the gem and add it to your application's Gemfile, execute:
13
13
 
14
14
  ```bash
15
- $ bundle add limit
15
+ $ bundle add co-limit
16
16
  ```
17
17
 
18
18
  If you are not using Bundler, you can install the gem directly by running:
19
19
 
20
20
  ```bash
21
- $ gem install limit
21
+ $ gem install co-limit
22
22
  ```
23
23
 
24
24
  ## Usage
@@ -85,7 +85,7 @@ You can configure the Redis connection either by passing the connection details
85
85
  ### Key Points:
86
86
 
87
87
  - **identifier_prefix**: A namespace prefix for Redis keys (e.g., `"access"`).
88
- - **limit_calculator**: A `Proc` that takes a key (e.g., `"user_id:site_name"`) and returns a hash with `max_requests` and `window_seconds`.
88
+ - **limit_calculator**: A `Lambda` that takes a key (e.g., `"user_id:site_name"`) and returns a hash with `max_requests` and `window_seconds`.
89
89
 
90
90
  ### Supported Rate Limiters:
91
91
 
data/lib/limit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Limit
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/limit.rb CHANGED
@@ -44,13 +44,13 @@ module Limit
44
44
  def initialize(identifier_prefix:, limit_calculator:, host: nil, port: nil, password: nil)
45
45
 
46
46
  # @param identifier_prefix: [String] A namespace prefix for redis keys for this limiter instance
47
- # @param limit_calculator: [Proc] A method that takes a key(String) and returns hash: {max_requests: Integer, window_seconds: Integer}
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'
51
51
  end
52
52
 
53
- raise ArgumentError, 'limit_calculator must be a Proc' unless limit_calculator.is_a?(Proc)
53
+ raise ArgumentError, 'limit_calculator must be a Lambda' unless limit_calculator.lambda?
54
54
 
55
55
  # Will be using the same connection across all instance unless wanted to connect to diff instance of redis
56
56
 
data/sig/limit/limit.rbs CHANGED
@@ -1,37 +1,37 @@
1
1
  type redis = untyped
2
2
 
3
3
  module Limit
4
- VERSION: String
5
4
 
6
- class BaseLimiter
7
- self.@redis: redis
8
- @logger: Logger
5
+ class BaseLimiter
6
+ self.@logger: Logger
7
+ self.@redis: redis
8
+ @logger: Logger
9
9
 
10
- @redis: redis | nil
10
+ @redis: redis | nil
11
11
 
12
- def self.connection: -> nil
12
+ def self.connection: -> nil
13
13
 
14
- def self.create_connection: (String, Integer, String) -> redis
14
+ def self.create_connection: (String, Integer, String) -> redis
15
15
 
16
- def self.log: (String, String) -> nil
16
+ def self.log: (String, String) -> nil
17
17
 
18
- def self.logger: -> Logger
18
+ def self.logger: -> Logger
19
19
 
20
- attr_reader identifier_prefix: String
21
- attr_reader limit_calculator: Proc
20
+ attr_reader identifier_prefix: String
21
+ attr_reader limit_calculator: Proc
22
22
 
23
- def initialize: -> untyped
23
+ def initialize: -> untyped
24
24
 
25
- def allowed?: (String) -> bool
25
+ def allowed?: (String) -> bool
26
26
 
27
- def get_current_limit: (String) -> Hash[String, Integer]
27
+ def get_current_limit: (String) -> Hash[String, Integer]
28
28
 
29
- def get_key: (String) -> String
29
+ def get_key: (String) -> String
30
30
 
31
- def current_micros: (nil) -> Integer
31
+ def current_micros: (nil) -> Integer
32
32
 
33
- def log: (String, String) -> nil
33
+ def log: (String, String) -> nil
34
34
 
35
- def redis_pipeline: () { (redis) -> untyped } -> untyped
35
+ def redis_pipeline: () { (redis) -> untyped } -> untyped
36
36
  end
37
37
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CosmicOppai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-29 00:00:00.000000000 Z
11
+ date: 2025-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis