Class: Rack::Attack::BannedIps

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/attack_extensions.rb

Class Method Summary collapse

Class Method Details

.ban!(ip, bantime) ⇒ Object



346
347
348
# File 'lib/rack/attack_extensions.rb', line 346

def ban!(ip, bantime)
  cache.write("#{key_prefix}:#{ip}", 1, bantime)
end

.banned?(ip) ⇒ Boolean

Returns:

  • (Boolean)


350
351
352
# File 'lib/rack/attack_extensions.rb', line 350

def banned?(ip)
  cache.read("#{key_prefix}:#{ip}") ? true : false
end

.full_key_prefixObject



359
360
361
# File 'lib/rack/attack_extensions.rb', line 359

def full_key_prefix
  "#{cache.prefix}:#{key_prefix}"
end

.ip_from_key(key) ⇒ Object



354
355
356
357
# File 'lib/rack/attack_extensions.rb', line 354

def ip_from_key(key)
  key = Rack::Attack.unprefix_key(key)
  key.sub "#{key_prefix}:", ''
end

.ipsObject



340
341
342
343
344
# File 'lib/rack/attack_extensions.rb', line 340

def ips
  prefixed_keys.map { |key|
    ip_from_key(key)
  }
end

.keysObject

Removes only the Rack::Attack.cache.prefix



334
335
336
337
338
# File 'lib/rack/attack_extensions.rb', line 334

def keys
  prefixed_keys.map { |key|
    Rack::Attack.unprefix_key(key)
  }
end

.prefixed_keysObject



329
330
331
# File 'lib/rack/attack_extensions.rb', line 329

def prefixed_keys
  Rack::Attack.all_keys.grep(/^#{full_key_prefix}:/)
end