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:, on_throttled: nil) ⇒ ThrottleParams

Returns a new instance of ThrottleParams.



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

def initialize(config:, key:, limit:, period:, on_throttled: nil)
  @config = config
  @key = key
  @limit = limit
  @period = period
  @on_throttled = on_throttled
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

#on_throttledObject (readonly)

Returns the value of attribute on_throttled.



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

def on_throttled
  @on_throttled
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



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

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

#redis_keyObject



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

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