Class: Ipecache::Plugins::Plugin
- Inherits:
-
Object
- Object
- Ipecache::Plugins::Plugin
show all
- Defined in:
- lib/ipecache/plugins/plugin.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Plugin
Returns a new instance of Plugin.
28
29
30
31
32
|
# File 'lib/ipecache/plugins/plugin.rb', line 28
def initialize(options = {})
@options = {
:payload => {}
}.merge(options)
end
|
Class Method Details
.hook(the_hook) ⇒ Object
When defining a hook, we define a method on the instance that corresponds to that hook. That will be fired when the hook is fired.
22
23
24
25
26
|
# File 'lib/ipecache/plugins/plugin.rb', line 22
def self.hook(the_hook)
self.send(:define_method, the_hook.to_sym) do
perform
end
end
|
.hooks(*the_hooks) ⇒ Object
This is a convenience method for defining multiple hooks in a single call.
16
17
18
|
# File 'lib/ipecache/plugins/plugin.rb', line 16
def self.hooks(*the_hooks)
[the_hooks].flatten.each{ |the_hook| hook(the_hook) }
end
|
.name(name = nil) ⇒ Object
This is the name of the plugin. It must correspond to the name in the yaml configuration file in order to load this plugin. If an attribute is passed in, the name is set to that given value. Otherwise, the name is returned.
7
8
9
10
11
12
13
|
# File 'lib/ipecache/plugins/plugin.rb', line 7
def self.name(name = nil)
if name.nil?
class_variable_get(:@@name)
else
class_variable_set(:@@name, name)
end
end
|
Instance Method Details
#continue_on_error ⇒ Object
46
47
48
|
# File 'lib/ipecache/plugins/plugin.rb', line 46
def continue_on_error
@options[:continue_on_error]
end
|
#enabled? ⇒ Boolean
34
35
36
|
# File 'lib/ipecache/plugins/plugin.rb', line 34
def enabled?
!(config.nil? || config.enabled == false)
end
|
#log_file ⇒ Object
42
43
44
|
# File 'lib/ipecache/plugins/plugin.rb', line 42
def log_file
@options[:log_file]
end
|
#name ⇒ Object
50
51
52
|
# File 'lib/ipecache/plugins/plugin.rb', line 50
def name
self.class.to_s
end
|
#plugin_puts(message) ⇒ Object
54
55
56
|
# File 'lib/ipecache/plugins/plugin.rb', line 54
def plugin_puts(message)
puts "#{name}: #{message}"
end
|
#plugin_puts_error(url, message) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/ipecache/plugins/plugin.rb', line 58
def plugin_puts_error(url,message)
if log_file
File.open(log_file, 'a') { |file| file.write("#{Time.now.getutc} #{url} #{name}: #{message}\n") }
end
puts "#{name}: #{message}"
end
|
#urls ⇒ Object
38
39
40
|
# File 'lib/ipecache/plugins/plugin.rb', line 38
def urls
@options[:urls]
end
|