module Bottleneck
Constants
- VERSION
Public Class Methods
check(ip)
click to toggle source
Run method call on Core
object
@param [String] A name to uniquely identify this rate limit. For example, '127.0.0.1'
# File lib/bottleneck.rb, line 12 def check(ip) Core.new(ip).run end
config()
click to toggle source
Load limits config file
@return [Hash] Hash for bottleneck.yml file
# File lib/bottleneck.rb, line 41 def config load_config("bottleneck.yml") end
init_storage()
click to toggle source
Init Redis Namespace storage
@return [Redis::Namespace] Redis::Namespace instance
# File lib/bottleneck.rb, line 34 def init_storage Redis::Namespace.new(:bottleneck, redis: redis_conn) end
redis_conn()
click to toggle source
Init Redis instance
@return [Redis] Redis instance
# File lib/bottleneck.rb, line 26 def redis_conn redis_conf = load_config("redis.yml") Redis.new(host: redis_conf["host"], port: redis_conf["port"]) end
storage()
click to toggle source
Init Redis Namespace storage
@return [Redis::Namespace] Redis::Namespace instance
# File lib/bottleneck.rb, line 19 def storage init_storage end
Private Class Methods
load_config(file)
click to toggle source
Load config file
@return [Hash] Hash with configuration
# File lib/bottleneck.rb, line 49 def load_config(file) root = (defined?(Rails) && Rails.respond_to?(:root) && Rails.root) || Dir.pwd path = "#{root}/config/#{file}" raise "No #{file} file found in your config directory!" unless File.exist?(path) YAML.load_file(path) end