Class: WEBrickNIO::ChainedBlock
- Defined in:
- lib/webricknio/block.rb
Overview
Wrapper that chains other blockers
Instance Method Summary collapse
- #add_ip(ip) ⇒ Object
- #block_ip?(ip) ⇒ Boolean
-
#initialize(options = {}) ⇒ ChainedBlock
constructor
A new instance of ChainedBlock.
- #load ⇒ Object
- #reload ⇒ Object
Methods inherited from BaseBlock
Constructor Details
#initialize(options = {}) ⇒ ChainedBlock
Returns a new instance of ChainedBlock.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/webricknio/block.rb', line 44 def initialize( = {}) begin load rescue Exception => ex puts ex create_default_chain end super # at_exit do # file = File.new(File.expand_path('block.yaml', File.dirname(__FILE__)), "w") # dump = YAML::dump(@chain) # file.write(dump) # file.close # end end |
Instance Method Details
#add_ip(ip) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/webricknio/block.rb', line 73 def add_ip(ip) @chain.each do |blocker| if blocker.valid? ip blocker.add_ip ip return true end end return false end |
#block_ip?(ip) ⇒ Boolean
83 84 85 86 87 88 89 90 |
# File 'lib/webricknio/block.rb', line 83 def block_ip?(ip) @chain.each do |blocker| if blocker.block_ip?(ip) return true end end return false end |
#load ⇒ Object
62 63 64 65 66 67 |
# File 'lib/webricknio/block.rb', line 62 def load file = File.new(File.('block.yaml', File.dirname(__FILE__)), "r") @chain = YAML::load(file) ensure_default_chain @chain puts @chain end |
#reload ⇒ Object
69 70 71 |
# File 'lib/webricknio/block.rb', line 69 def reload load end |