Class: WEBrickNIO::ChainedBlock

Inherits:
BaseBlock show all
Defined in:
lib/webricknio/block.rb

Overview

Wrapper that chains other blockers

Instance Method Summary collapse

Methods inherited from BaseBlock

inherited, #valid?

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(options = {})
  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

Returns:

  • (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

#loadObject



62
63
64
65
66
67
# File 'lib/webricknio/block.rb', line 62

def load
  file = File.new(File.expand_path('block.yaml', File.dirname(__FILE__)), "r")
  @chain = YAML::load(file)
  ensure_default_chain @chain
  puts @chain
end

#reloadObject



69
70
71
# File 'lib/webricknio/block.rb', line 69

def reload
  load
end