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



43
44
45
46
47
48
49
# File 'lib/resque_mailer.rb', line 43

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

Instance Method Details

#current_envObject



35
36
37
38
39
40
41
# File 'lib/resque_mailer.rb', line 35

def current_env
  if defined?(Rails)
    ::Resque::Mailer.current_env || ::Rails.env
  else
    ::Resque::Mailer.current_env
  end
end

#deliver?Boolean

Returns:

  • (Boolean)


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

def deliver?
  true
end

#excluded_environment?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#perform(action, serialized_args) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/resque_mailer.rb', line 51

def perform(action, serialized_args)
  begin
    args = ::Resque::Mailer.argument_serializer.deserialize(serialized_args)
    message = ::Resque::Mailer.prepare_message(self, action, *args)
    if message.respond_to?(:deliver_now)
      message.deliver_now
    else
      message.deliver
    end
  rescue Exception => ex
    if Mailer.error_handler
      Mailer.error_handler.call(self, message, ex, action, args)
    else
      if logger
        logger.error "Unable to deliver email [#{action}]: #{ex}"
        logger.error ex.backtrace.join("\n\t")
      end

      raise ex
    end
  end
end

#queueObject



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

def queue
  @queue || ::Resque::Mailer.default_queue_name
end

#queue=(name) ⇒ Object



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

def queue=(name)
  @queue = name
end

#resqueObject



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

def resque
  ::Resque::Mailer.default_queue_target
end