Class: Rack::Attack::BannedIps
- Inherits:
-
Object
- Object
- Rack::Attack::BannedIps
- Defined in:
- lib/rack/attack_extensions.rb
Class Method Summary collapse
- .ban!(ip, bantime) ⇒ Object
- .banned?(ip) ⇒ Boolean
- .full_key_prefix ⇒ Object
- .ip_from_key(key) ⇒ Object
- .ips ⇒ Object
-
.keys ⇒ Object
Removes only the Rack::Attack.cache.prefix.
- .prefixed_keys ⇒ Object
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
350 351 352 |
# File 'lib/rack/attack_extensions.rb', line 350 def banned?(ip) cache.read("#{key_prefix}:#{ip}") ? true : false end |
.full_key_prefix ⇒ Object
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 |
.ips ⇒ Object
340 341 342 343 344 |
# File 'lib/rack/attack_extensions.rb', line 340 def ips prefixed_keys.map { |key| ip_from_key(key) } end |
.keys ⇒ Object
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_keys ⇒ Object
329 330 331 |
# File 'lib/rack/attack_extensions.rb', line 329 def prefixed_keys Rack::Attack.all_keys.grep(/^#{full_key_prefix}:/) end |