mirror of https://github.com/docusealco/docuseal
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							20 lines
						
					
					
						
							373 B
						
					
					
				
			
		
		
	
	
							20 lines
						
					
					
						
							373 B
						
					
					
				| # frozen_string_literal: true
 | |
| 
 | |
| module RateLimit
 | |
|   LimitApproached = Class.new(StandardError)
 | |
| 
 | |
|   STORE = ActiveSupport::Cache::MemoryStore.new
 | |
| 
 | |
|   module_function
 | |
| 
 | |
|   def call(key, limit:, ttl:, enabled: Docuseal.multitenant?)
 | |
|     return true unless enabled
 | |
| 
 | |
|     value = STORE.increment(key, 1, expires_in: ttl)
 | |
| 
 | |
|     raise LimitApproached if value > limit
 | |
| 
 | |
|     true
 | |
|   end
 | |
| end
 |