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 =
{ only_paths: [], except_paths: [], status: 403, text: 'Forbidden (Temporarily Blocked by Rules)' }.freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#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.
21 22 23 24 25 |
# File 'lib/rack/dedos/filters/base.rb', line 21 def initialize(app, = {}) @app = app @options = DEFAULT_OPTIONS.merge() @details = nil end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
15 16 17 |
# File 'lib/rack/dedos/filters/base.rb', line 15 def app @app end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
17 18 19 |
# File 'lib/rack/dedos/filters/base.rb', line 17 def details @details end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/rack/dedos/filters/base.rb', line 16 def @options end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rack/dedos/filters/base.rb', line 27 def call(env) request = Rack::Request.new(env) ip = real_ip(request) if !apply?(request) || allowed?(request, ip) app.call(env) else = "rack-dedos: request #{request.path} from #{ip} blocked by #{self.class}" warn([, details].compact.join(": ")) [[:status], { 'Content-Type' => 'text/plain' }, [[:text]]] end end |