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
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
296 297 298 |
# File 'lib/rack/attack_extensions.rb', line 296 def banned?(ip) cache.read("#{key_prefix}:#{ip}") ? true : false end |
.full_key_prefix ⇒ Object
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 |
.ips ⇒ Object
286 287 288 289 290 |
# File 'lib/rack/attack_extensions.rb', line 286 def ips prefixed_keys.map { |key| ip_from_key(key) } end |
.keys ⇒ Object
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_keys ⇒ Object
275 276 277 |
# File 'lib/rack/attack_extensions.rb', line 275 def prefixed_keys cache.store.keys.grep(/^#{full_key_prefix}:/) end |