Class: ActionMessager::Base

Inherits:
Object
  • Object
show all
Includes:
ActionController::UrlWriter
Defined in:
lib/action_messager/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#recipientsObject

Returns the value of attribute recipients.



29
30
31
# File 'lib/action_messager/base.rb', line 29

def recipients
  @recipients
end

Class Method Details

.connectionObject

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/action_messager/base.rb', line 8

def connection
  raise ArgumentError.new('You must supply jabber credentials to use ActionMessager') unless [jabber_settings[:username], jabber_settings[:password]].select(&:blank?).empty?
  @connection ||= Jabber::Simple.new(jabber_settings[:username], jabber_settings[:password])
end

.deliver(method, *args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/action_messager/base.rb', line 17

def deliver(method, *args)
  messager = new
  msg      = messager.send(method, *args)
  
  messager.recipients.each do |recipient|
    connection.deliver recipient, msg
  end
end

.method_missing(method, *args) ⇒ Object



13
14
15
# File 'lib/action_messager/base.rb', line 13

def method_missing(method, *args)
  method.to_s =~ /deliver_.+?/ ? deliver(method.to_s.gsub(/deliver_/, '').intern, *args) : super
end