Class: WebShield::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/web_shield/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
14
15
# File 'lib/web_shield/config.rb', line 8

def initialize
  @shields = []
  @shield_counter = 0

  @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_responseObject

Returns the value of attribute blocked_response.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def blocked_response
  @blocked_response
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def logger
  @logger
end

#shieldsObject (readonly)

Returns the value of attribute shields.



6
7
8
# File 'lib/web_shield/config.rb', line 6

def shields
  @shields
end

#storeObject

Returns the value of attribute store.



5
6
7
# File 'lib/web_shield/config.rb', line 5

def store
  @store
end

#user_parserObject

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



33
34
35
36
# File 'lib/web_shield/config.rb', line 33

def build_shield(path_matcher, options, shield_class = ThrottleShield)
  shields << shield_class.new(@shield_counter += 1, path_matcher, options, self)
  logger.info("Build shield #{shields.last.id} #{path_matcher} #{options}")
end