Class: Whoosh::App::RateLimitBuilder
- Inherits:
-
Object
- Object
- Whoosh::App::RateLimitBuilder
- Defined in:
- lib/whoosh/app.rb
Instance Method Summary collapse
- #build ⇒ Object
- #default(limit:, period:) ⇒ Object
-
#initialize ⇒ RateLimitBuilder
constructor
A new instance of RateLimitBuilder.
- #on_store_failure(strategy) ⇒ Object
- #rule(path, limit:, period:) ⇒ Object
- #tier(name, limit: nil, period: nil, unlimited: false) ⇒ Object
Constructor Details
#initialize ⇒ RateLimitBuilder
Returns a new instance of RateLimitBuilder.
708 709 710 711 712 713 714 |
# File 'lib/whoosh/app.rb', line 708 def initialize @default_limit = 60 @default_period = 60 @rules = [] @tiers = [] @on_store_failure = :fail_open end |
Instance Method Details
#build ⇒ Object
733 734 735 736 737 738 739 740 741 742 |
# File 'lib/whoosh/app.rb', line 733 def build limiter = Auth::RateLimiter.new( default_limit: @default_limit, default_period: @default_period, on_store_failure: @on_store_failure ) @rules.each { |r| limiter.rule(r[:path], limit: r[:limit], period: r[:period]) } @tiers.each { |t| limiter.tier(t[:name], limit: t[:limit], period: t[:period], unlimited: t[:unlimited]) } limiter end |
#default(limit:, period:) ⇒ Object
716 717 718 719 |
# File 'lib/whoosh/app.rb', line 716 def default(limit:, period:) @default_limit = limit @default_period = period end |
#on_store_failure(strategy) ⇒ Object
729 730 731 |
# File 'lib/whoosh/app.rb', line 729 def on_store_failure(strategy) @on_store_failure = strategy end |
#rule(path, limit:, period:) ⇒ Object
721 722 723 |
# File 'lib/whoosh/app.rb', line 721 def rule(path, limit:, period:) @rules << { path: path, limit: limit, period: period } end |
#tier(name, limit: nil, period: nil, unlimited: false) ⇒ Object
725 726 727 |
# File 'lib/whoosh/app.rb', line 725 def tier(name, limit: nil, period: nil, unlimited: false) @tiers << { name: name, limit: limit, period: period, unlimited: unlimited } end |