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



292
293
294
# File 'lib/rack/attack_extensions.rb', line 292

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

.banned?(ip) ⇒ Boolean

Returns:

  • (Boolean)


296
297
298
# File 'lib/rack/attack_extensions.rb', line 296

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

.full_key_prefixObject



305
306
307
# File 'lib/rack/attack_extensions.rb', line 305

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

.ip_from_key(key) ⇒ Object



300
301
302
303
# File 'lib/rack/attack_extensions.rb', line 300

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

.ipsObject



286
287
288
289
290
# File 'lib/rack/attack_extensions.rb', line 286

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

.keysObject

Removes only the Rack::Attack.cache.prefix



280
281
282
283
284
# File 'lib/rack/attack_extensions.rb', line 280

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

.prefixed_keysObject



275
276
277
# File 'lib/rack/attack_extensions.rb', line 275

def prefixed_keys
  cache.store.keys.grep(/^#{full_key_prefix}:/)
end