Class: WebShield::Config
- Inherits:
-
Object
- Object
- WebShield::Config
- Defined in:
- lib/web_shield/config.rb
Instance Attribute Summary collapse
-
#blocked_response ⇒ Object
Returns the value of attribute blocked_response.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#shields ⇒ Object
readonly
Returns the value of attribute shields.
-
#store ⇒ Object
Returns the value of attribute store.
-
#user_parser ⇒ Object
Returns the value of attribute user_parser.
Instance Method Summary collapse
-
#build_shield(path_matcher, options, shield_class = ThrottleShield) ⇒ Object
return shield.
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 |
# File 'lib/web_shield/config.rb', line 8 def initialize @shields = [] @shield_counter = 0 @id_prefix = Time.now.to_f.to_s @user_parser = Proc.new {|req| req.ip } @blocked_response = Proc.new {|req| [429, {}, ['Too Many Requests']] } @logger = Logger.new($stdout) end |
Instance Attribute Details
#blocked_response ⇒ Object
Returns the value of attribute blocked_response.
5 6 7 |
# File 'lib/web_shield/config.rb', line 5 def blocked_response @blocked_response end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/web_shield/config.rb', line 5 def logger @logger end |
#shields ⇒ Object (readonly)
Returns the value of attribute shields.
6 7 8 |
# File 'lib/web_shield/config.rb', line 6 def shields @shields end |
#store ⇒ Object
Returns the value of attribute store.
5 6 7 |
# File 'lib/web_shield/config.rb', line 5 def store @store end |
#user_parser ⇒ Object
Returns the value of attribute user_parser.
5 6 7 |
# File 'lib/web_shield/config.rb', line 5 def user_parser @user_parser end |
Instance Method Details
#build_shield(path_matcher, options, shield_class = ThrottleShield) ⇒ Object
return shield
35 36 37 38 39 40 |
# File 'lib/web_shield/config.rb', line 35 def build_shield(path_matcher, , shield_class = ThrottleShield) shield_class.new(generate_id, path_matcher, , self).tap do |shield| shields << shield logger.info("Build #{shield.shield_name} #{path_matcher} #{}") end end |