Class: Eye::Notify
Defined Under Namespace
Classes: Jabber, Mail
Constant Summary
collapse
- TYPES =
{:mail => "Mail", :jabber => "Jabber"}
- TIMEOUT =
1.minute
Instance Attribute Summary
#defaults, #should_bes, #validates, #variants
#logger
Class Method Summary
collapse
Instance Method Summary
collapse
inherited, param, validate
Constructor Details
#initialize(options = {}, message_h = {}) ⇒ Notify
Returns a new instance of Notify.
44
45
46
47
48
49
50
|
# File 'lib/eye/notify.rb', line 44
def initialize(options = {}, message_h = {})
@logger = Eye::Logger.new("#{self.class.name.downcase} - #{options[:contact]}")
debug "created notifier #{options}"
@message_h = message_h
@options = options
end
|
Class Method Details
.get_class(type) ⇒ Object
11
12
13
14
15
|
# File 'lib/eye/notify.rb', line 11
def self.get_class(type)
klass = eval("Eye::Notify::#{TYPES[type]}") rescue nil
raise "Unknown notify #{type}" unless klass
klass
end
|
.notify(contact, message_h) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/eye/notify.rb', line 21
def self.notify(contact, message_h)
settings = Eye::Control.settings
needed_hash = (settings[:contacts] || {})[contact.to_s]
return if needed_hash.blank?
create_proc = lambda do |nh|
type = nh[:type]
config = (settings[type] || {}).merge(nh[:opts] || {}).merge(:contact => nh[:contact])
klass = get_class(type)
notify = klass.new(config, message_h)
notify.async_notify if notify
end
if needed_hash.is_a?(Array)
needed_hash.each{|nh| create_proc[nh] }
else
create_proc[needed_hash]
end
end
|
.validate!(options) ⇒ Object
17
18
19
|
# File 'lib/eye/notify.rb', line 17
def self.validate!(options)
get_class(options[:type]).validate(options)
end
|
Instance Method Details
#async_notify ⇒ Object
52
53
54
55
|
# File 'lib/eye/notify.rb', line 52
def async_notify
async.notify
after(TIMEOUT){ terminate }
end
|
#execute ⇒ Object
64
65
66
|
# File 'lib/eye/notify.rb', line 64
def execute
raise "realize me"
end
|
#message_body ⇒ Object
74
75
76
|
# File 'lib/eye/notify.rb', line 74
def message_body
"#{message_subject} at #{msg_at.to_s(:short)}"
end
|
#message_subject ⇒ Object
70
71
72
|
# File 'lib/eye/notify.rb', line 70
def message_subject
"[#{msg_host}] [#{msg_full_name}] #{msg_message}"
end
|
#notify ⇒ Object
57
58
59
60
61
62
|
# File 'lib/eye/notify.rb', line 57
def notify
debug "start notify #{@message_h}"
execute
debug "end notify #{@message_h}"
terminate
end
|