Class: TextMessage::Delivery

Inherits:
Delegator
  • Object
show all
Includes:
DeliveryMethods
Defined in:
lib/text_message_rails/delivery.rb

Overview

TextMessage Delivery Proxy

The Delivery class is the class returned by the TextMessage::Base actions. It is used to enable lazy processing of the actions.

Instance Method Summary collapse

Methods included from DeliveryMethods

#deliver_later!, #deliver_now!

Constructor Details

#initialize(text_message_class, text_message_method, *args) ⇒ Delivery

Creates a new Delivery proxy. By providing a TextMessage::Base subclass text_message_class, a method name to call text_message_method and a set of arguments to this method args, we allow for lazy processing of the text_message action.



14
15
16
17
18
# File 'lib/text_message_rails/delivery.rb', line 14

def initialize(text_message_class, text_message_method, *args)
  @text_message_class = text_message_class.kind_of?(Class) ? text_message_class : text_message_class.constantize
  @text_message_method = text_message_method
  @args = args
end

Instance Method Details

#__getobj__Object

Needed by Decorator superclass



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

def __getobj__ #:nodoc:
  @obj ||= @text_message_class.send(:new, @text_message_method, *@args)
end

#bodyObject

computes the body of the TextMessage



26
27
28
# File 'lib/text_message_rails/delivery.rb', line 26

def body
  renderer.render(view_context, template: "#{templates_dir}/#{@text_message_method}")
end

#templates_dirObject

The name of the templates which holds the templates. Usually it is the name of the class with underscores, something like:

TextMessageDemo.new.templates_dir => "text_message demo"
# so for exemple TextMessageDemo#toto will lookup for text_message_demo/toto{.text.erb}


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

def templates_dir
  @text_message_class.to_s.underscore
end