def self.contact(kind)
self.internal_init
begin
c = Contact.generate(kind)
rescue NoSuchContactError => e
abort e.message
end
yield(c) if block_given?
c.prepare
existing_contact = self.contacts[c.name]
if self.running && existing_contact
self.uncontact(existing_contact)
end
if self.contacts[c.name] || self.contact_groups[c.name]
applog(nil, :warn, "Contact name '#{c.name}' already used for a Contact or Contact Group")
return
end
unless Contact.valid?(c) && c.valid?
abort "Exiting on invalid contact"
end
self.contacts[c.name] = c
if c.group
if self.contacts[c.group]
abort "Contact Group name '#{c.group}' already used for a Contact"
end
self.contact_groups[c.group] ||= []
self.contact_groups[c.group] << c
end
end