Class: Rack::Dedos::Filters::Base
- Inherits:
-
Object
- Object
- Rack::Dedos::Filters::Base
- Defined in:
- lib/rack/dedos/filters/base.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ status: 403, text: 'Forbidden (Temporarily Blocked by Rules)' }
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(app, options = {}) ⇒ Base
Returns a new instance of Base.
18 19 20 21 |
# File 'lib/rack/dedos/filters/base.rb', line 18 def initialize(app, = {}) @app = app @options = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
13 14 15 |
# File 'lib/rack/dedos/filters/base.rb', line 13 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/rack/dedos/filters/base.rb', line 14 def @options end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/dedos/filters/base.rb', line 23 def call(env) request = Rack::Request.new(env) ip = real_ip(request) if allowed?(request, ip) app.call(env) else warn("rack-dedos: request from #{ip} blocked by #{self.class} `#{@country_code.inspect}'") [[:status], { 'Content-Type' => 'text/plain' }, [[:text]]] end end |