Class: WebShield::Shield

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

Direct Known Subclasses

IPShield, ThrottleShield

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, shield_path, options, config) ⇒ Shield

Returns a new instance of Shield.



7
8
9
10
11
12
13
# File 'lib/web_shield/shield.rb', line 7

def initialize(id, shield_path, options, config)
  @id = id
  @shield_path = shield_path
  @path_matcher = build_path_matcher(shield_path)
  @options = hash_to_symbol_keys(options)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#path_matcherObject (readonly)

Returns the value of attribute path_matcher.



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

def path_matcher
  @path_matcher
end

#shield_pathObject (readonly)

Returns the value of attribute shield_path.



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

def shield_path
  @shield_path
end

Instance Method Details

#dictatorial?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/web_shield/shield.rb', line 20

def dictatorial?
  @options[:dictatorial]
end

#filter(request) ⇒ Object

Returns: :pass, :block, [:response, rack_response], nil

Raises:



16
17
18
# File 'lib/web_shield/shield.rb', line 16

def filter(request)
  raise Error, "implement me"
end

#shield_nameObject



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

def shield_name
  self.class.name.split('::', 2).last + "\##{id}"
end

#write_log(severity, msg) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/web_shield/shield.rb', line 24

def write_log(severity, msg)
  case svrt = severity.to_sym
  when :debug, :info, :warn, :error
    config.logger.send(svrt, "#{shield_name} #{msg}")
  else
    raise "Invalid log severity '#{svrt}'"
  end
end