Class: RateLimit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rate_limit/config.rb,
lib/rate_limit/config/defaults.rb,
lib/rate_limit/config/file_loader.rb

Defined Under Namespace

Modules: Defaults, FileLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



17
18
19
20
21
22
23
# File 'lib/rate_limit/config.rb', line 17

def initialize
  @redis             = Redis.new
  @fail_safe         = true
  @limits_file_path  = Defaults::LIMITS_FILE_PATH
  @default_interval  = Defaults::WINDOW_INTERVAL
  @default_threshold = Defaults::WINDOW_THRESHOLD
end

Instance Attribute Details

#default_intervalObject

Returns the value of attribute default_interval.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def default_interval
  @default_interval
end

#default_thresholdObject

Returns the value of attribute default_threshold.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def default_threshold
  @default_threshold
end

#fail_safeObject

Returns the value of attribute fail_safe.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def fail_safe
  @fail_safe
end

#limits_file_pathObject

Returns the value of attribute limits_file_path.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def limits_file_path
  @limits_file_path
end

#on_failureObject

Returns the value of attribute on_failure.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def on_failure
  @on_failure
end

#on_successObject

Returns the value of attribute on_success.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def on_success
  @on_success
end

#redisObject

Returns the value of attribute redis.



9
10
11
# File 'lib/rate_limit/config.rb', line 9

def redis
  @redis
end

Instance Method Details

#failure_callback(*args) ⇒ Object



33
34
35
# File 'lib/rate_limit/config.rb', line 33

def failure_callback(*args)
  on_failure&.call(*args)
end

#raw_limits_for(topic) ⇒ Object



25
26
27
# File 'lib/rate_limit/config.rb', line 25

def raw_limits_for(topic)
  raw_limits[topic] || Defaults.raw_limits
end

#success_callback(*args) ⇒ Object



29
30
31
# File 'lib/rate_limit/config.rb', line 29

def success_callback(*args)
  on_success&.call(*args)
end