Class: Eye::Notify
Defined Under Namespace
Classes: Custom, 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.
50
51
52
53
54
55
|
# File 'lib/eye/notify.rb', line 50
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
44
45
46
|
# 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
rescue Exception, Timeout::Error => ex
log_ex(ex)
end
|
.register(base) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/eye/notify.rb', line 87
def self.register(base)
name = base.to_s.gsub("Eye::Notify::", '')
type = name.underscore.to_sym
Eye::Notify::TYPES[type] = name
Eye::Notify.const_set(name, base)
Eye::Dsl::ConfigOpts.add_notify(type)
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
61
62
63
64
|
# File 'lib/eye/notify.rb', line 61
def async_notify
async.notify
after(TIMEOUT){ terminate }
end
|
#execute ⇒ Object
73
74
75
|
# File 'lib/eye/notify.rb', line 73
def execute
raise "realize me"
end
|
#logger_sub_tag ⇒ Object
57
58
59
|
# File 'lib/eye/notify.rb', line 57
def logger_sub_tag
@options[:contact]
end
|
#message_body ⇒ Object
83
84
85
|
# File 'lib/eye/notify.rb', line 83
def message_body
"#{message_subject} at #{msg_at.to_s(:short)}"
end
|
#message_subject ⇒ Object
79
80
81
|
# File 'lib/eye/notify.rb', line 79
def message_subject
"[#{msg_host}] [#{msg_full_name}] #{msg_message}"
end
|
#notify ⇒ Object
66
67
68
69
70
71
|
# File 'lib/eye/notify.rb', line 66
def notify
debug "start notify #{@message_h}"
execute
debug "end notify #{@message_h}"
terminate
end
|