Class: Resque::Mailer::MessageDecoy

Inherits:
Object
  • Object
show all
Defined in:
lib/resque_mailer.rb

Instance Method Summary collapse

Constructor Details

#initialize(mailer_class, method_name, *args) ⇒ MessageDecoy

Returns a new instance of MessageDecoy.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/resque_mailer.rb', line 61

def initialize(mailer_class, method_name, *args)
  @mailer_class = mailer_class
  @method_name = method_name
  *@args = *args.map do |object|
    if object.is_a?(ActiveRecord::Base)
      {:class_name => object.class.name, :id => object.id}
    else
      object
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



91
92
93
# File 'lib/resque_mailer.rb', line 91

def method_missing(method_name, *args)
  actual_message.send(method_name, *args)
end

Instance Method Details

#actual_messageObject



77
78
79
# File 'lib/resque_mailer.rb', line 77

def actual_message
  @actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
end

#deliverObject



81
82
83
84
85
# File 'lib/resque_mailer.rb', line 81

def deliver
  if @mailer_class.deliver?
    resque.enqueue(@mailer_class, @method_name, *@args)
  end
end

#deliver!Object



87
88
89
# File 'lib/resque_mailer.rb', line 87

def deliver!
  actual_message.deliver!
end

#resqueObject



73
74
75
# File 'lib/resque_mailer.rb', line 73

def resque
  ::Resque::Mailer.default_queue_target
end