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
Class Method Summary
collapse
Instance Method Summary
collapse
inherited, param, validate
Constructor Details
#initialize(options = {}, message_h = {}) ⇒ Notify
Returns a new instance of Notify.
47
48
49
50
51
52
|
# File 'lib/eye/notify.rb', line 47
def initialize(options = {}, message_h = {})
@message_h = message_h
@options = options
debug "created notifier #{options}"
end
|
Class Method Details
.get_class(type) ⇒ Object
10
11
12
13
14
|
# File 'lib/eye/notify.rb', line 10
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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/eye/notify.rb', line 20
def self.notify(contact, message_h)
contact = contact.to_s
settings = Eye::Control.settings
needed_hash = (settings[:contacts] || {})[contact]
if needed_hash.blank?
error "not found contact #{contact}! something wrong with config"
return
end
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
16
17
18
|
# File 'lib/eye/notify.rb', line 16
def self.validate!(options)
get_class(options[:type]).validate(options)
end
|
Instance Method Details
#async_notify ⇒ Object
58
59
60
61
|
# File 'lib/eye/notify.rb', line 58
def async_notify
async.notify
after(TIMEOUT){ terminate }
end
|
#execute ⇒ Object
70
71
72
|
# File 'lib/eye/notify.rb', line 70
def execute
raise "realize me"
end
|
#logger_sub_tag ⇒ Object
54
55
56
|
# File 'lib/eye/notify.rb', line 54
def logger_sub_tag
@options[:contact]
end
|
#message_body ⇒ Object
80
81
82
|
# File 'lib/eye/notify.rb', line 80
def message_body
"#{message_subject} at #{msg_at.to_s(:short)}"
end
|
#message_subject ⇒ Object
76
77
78
|
# File 'lib/eye/notify.rb', line 76
def message_subject
"[#{msg_host}] [#{msg_full_name}] #{msg_message}"
end
|
#notify ⇒ Object
63
64
65
66
67
68
|
# File 'lib/eye/notify.rb', line 63
def notify
debug "start notify #{@message_h}"
execute
debug "end notify #{@message_h}"
terminate
end
|