Class: BruteTools::Checker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/brutetools/base/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/brutetools/base/checker.rb', line 8

def initialize(options = {})
  @data_provider = options.delete(:data_provider)
  @proxy_list = options.delete(:proxy_list)
  
  @callbacks = {}
  load_callbacks(options.delete(:callbacks)) if options.key?(:callbacks)
  
  # Load default config
  config.merge!({
    :debug => false
  })
  
  # Load options left to config
  config.merge!(options)
end

Instance Attribute Details

#configObject (readonly)

Config is used to store configuration



25
26
27
# File 'lib/brutetools/base/checker.rb', line 25

def config
  @config
end

#data_providerObject

Returns the value of attribute data_provider.



4
5
6
# File 'lib/brutetools/base/checker.rb', line 4

def data_provider
  @data_provider
end

#proxy_listObject

Returns the value of attribute proxy_list.



5
6
7
# File 'lib/brutetools/base/checker.rb', line 5

def proxy_list
  @proxy_list
end

Instance Method Details

#add_callback(name, proc = nil, &block) ⇒ Object

Adds a new callback for specified name When passed both ‘proc` and block, two callbacks are added



31
32
33
34
35
36
# File 'lib/brutetools/base/checker.rb', line 31

def add_callback(name, proc = nil, &block)
  name = name.to_sym
  @callbacks[name] ||= []
  @callbacks[name].concat([proc, block].compact)
  self
end

#get_registered_callbacks(name) ⇒ Object

Can be overwritten by implementation to extend callbacks



46
47
48
# File 'lib/brutetools/base/checker.rb', line 46

def get_registered_callbacks(name)
  @callbacks[name.to_sym]
end

#load_callbacks(callbacks = {}) ⇒ Object

Adds callbacks from hash { :callback_name => proc { … } }



40
41
42
43
# File 'lib/brutetools/base/checker.rb', line 40

def load_callbacks(callbacks = {})
  callbacks.each{ |name, block| add_callback(name, block) }
  self
end

#runObject

This is where all the work goes



58
59
60
# File 'lib/brutetools/base/checker.rb', line 58

def run
  raise "You must implement this!"
end

#run_callback(name, *args) ⇒ Object

Calls all callbacks registred for the specific name



51
52
53
54
55
# File 'lib/brutetools/base/checker.rb', line 51

def run_callback(name, *args)
  procs = get_registered_callbacks(name)
  procs.each{ |proc| proc.call(*args) }
  self
end