Class: BruteTools::Checker::Base
- Inherits:
-
Object
- Object
- BruteTools::Checker::Base
- Defined in:
- lib/brutetools/base/checker.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Config is used to store configuration.
-
#data_provider ⇒ Object
Returns the value of attribute data_provider.
-
#proxy_list ⇒ Object
Returns the value of attribute proxy_list.
Instance Method Summary collapse
-
#add_callback(name, proc = nil, &block) ⇒ Object
Adds a new callback for specified name When passed both ‘proc` and block, two callbacks are added.
-
#get_registered_callbacks(name) ⇒ Object
Can be overwritten by implementation to extend callbacks.
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#load_callbacks(callbacks = {}) ⇒ Object
Adds callbacks from hash { :callback_name => proc { … } }.
-
#run ⇒ Object
This is where all the work goes.
-
#run_callback(name, *args) ⇒ Object
Calls all callbacks registred for the specific name.
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( = {}) @data_provider = .delete(:data_provider) @proxy_list = .delete(:proxy_list) @callbacks = {} load_callbacks(.delete(:callbacks)) if .key?(:callbacks) # Load default config config.merge!({ :debug => false }) # Load options left to config config.merge!() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Config is used to store configuration
25 26 27 |
# File 'lib/brutetools/base/checker.rb', line 25 def config @config end |
#data_provider ⇒ Object
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_list ⇒ Object
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 |
#run ⇒ Object
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 |