Class: Spree::SendWithUsMailer::Base

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
lib/spree_sendwithus/mailer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, *args) ⇒ Base

Returns a new instance of Base.



37
38
39
40
41
# File 'lib/spree_sendwithus/mailer.rb', line 37

def initialize(method_name, *args)
  @message = Spree::SendWithUs::Message.new
  @action = method_name
  self.send(method_name, *args)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#messageObject (readonly)

Returns the value of attribute message.



34
35
36
# File 'lib/spree_sendwithus/mailer.rb', line 34

def message
  @message
end

Class Method Details

.default(value = nil) ⇒ Object



9
10
11
12
# File 'lib/spree_sendwithus/mailer.rb', line 9

def default(value = nil)
  self.defaults = defaults.merge(value).freeze if value
  defaults
end

.mailer_methodsObject



14
15
16
17
18
19
# File 'lib/spree_sendwithus/mailer.rb', line 14

def mailer_methods
  methods = public_instance_methods - superclass.public_instance_methods

  # Reject route helper methods.
  methods.reject{ |m| m.to_s.end_with?("_url", "_path") }
end

.method_missing(method_name, *args) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/spree_sendwithus/mailer.rb', line 21

def method_missing(method_name, *args)
  if mailer_methods.include?(method_name.to_sym)
    new(method_name, *args).message
  else
    super(method_name, *args)
  end
end

.respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/spree_sendwithus/mailer.rb', line 29

def respond_to?(symbol, include_private = false)
  super || mailer_methods.include?(symbol)
end

Instance Method Details

#assign(key, value) ⇒ Object



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

def assign(key, value)
  @message.assign(key, value)
end

#mail(params = {}) ⇒ Object



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

def mail(params = {})
  @message.merge!(self.class.defaults.merge(params))
end