Module: Resque::Mailer::ClassMethods

Defined in:
lib/resque_mailer.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/resque_mailer.rb', line 25

def method_missing(method_name, *args)
  return super if environment_excluded?

  if action_methods.include?(method_name.to_s)
    MessageDecoy.new(self, method_name, *args)
  else
    super
  end
end

Instance Method Details

#current_envObject



21
22
23
# File 'lib/resque_mailer.rb', line 21

def current_env
  ::Rails.env
end

#deliver?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/resque_mailer.rb', line 55

def deliver?
  true
end

#environment_excluded?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/resque_mailer.rb', line 39

def environment_excluded?
  !ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
end

#excluded_environment?(name) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/resque_mailer.rb', line 51

def excluded_environment?(name)
  ::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
end

#perform(action, *args) ⇒ Object



35
36
37
# File 'lib/resque_mailer.rb', line 35

def perform(action, *args)
  self.send(:new, action, *args.map { |o| o.is_a?(Hash) && o.has_key?("class_name") && o.has_key?("id") ? o["class_name"].constantize.find(o["id"]) : o }).message.deliver
end

#queueObject



43
44
45
# File 'lib/resque_mailer.rb', line 43

def queue
  ::Resque::Mailer.default_queue_name
end

#resqueObject



47
48
49
# File 'lib/resque_mailer.rb', line 47

def resque
  ::Resque::Mailer.default_queue_target
end