Class: SpeedLimiter::ThrottleParams

Inherits:
Object
  • Object
show all
Defined in:
lib/speed_limiter/throttle_params.rb

Overview

Throttle params model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, key:, limit:, period:, **options) ⇒ ThrottleParams



8
9
10
11
12
13
14
# File 'lib/speed_limiter/throttle_params.rb', line 8

def initialize(config:, key:, limit:, period:, **options)
  @config = config
  @key = key
  @limit = limit
  @period = period
  @options = options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/speed_limiter/throttle_params.rb', line 16

def config
  @config
end

#keyObject (readonly)

Returns the value of attribute key.



16
17
18
# File 'lib/speed_limiter/throttle_params.rb', line 16

def key
  @key
end

#limitObject (readonly)

Returns the value of attribute limit.



16
17
18
# File 'lib/speed_limiter/throttle_params.rb', line 16

def limit
  @limit
end

#periodObject (readonly)

Returns the value of attribute period.



16
17
18
# File 'lib/speed_limiter/throttle_params.rb', line 16

def period
  @period
end

Instance Method Details

#create_state(count: nil, ttl: nil) ⇒ Object



30
31
32
# File 'lib/speed_limiter/throttle_params.rb', line 30

def create_state(count: nil, ttl: nil)
  State.new(params: self, count: count, ttl: ttl)
end

#on_throttledObject



18
19
20
# File 'lib/speed_limiter/throttle_params.rb', line 18

def on_throttled
  @options[:on_throttled]
end

#redis_keyObject



26
27
28
# File 'lib/speed_limiter/throttle_params.rb', line 26

def redis_key
  "#{config.prefix}:#{key}"
end

#retryObject



22
23
24
# File 'lib/speed_limiter/throttle_params.rb', line 22

def retry
  @options[:retry]
end