Class: TextMessage::Controller

Inherits:
AbstractController::Base
  • Object
show all
Includes:
AbstractController::Callbacks, AbstractController::Helpers, AbstractController::Logger, AbstractController::Rendering, Rendering
Defined in:
lib/text_message_rails/controller.rb

Overview

TextMessage controller base class

This class acts as a controller, similar to ActionMailer::Controller subclasses. To use it:

- implement action methods as in a "usual" controller

 class TextMessageTest < TextMessage::Controller

   # Will render app/views/sms_test/toto.(...), passing it the instance variables
   def toto
     @tutu = 4
   end

 end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rendering

included, #render_to_body, #renderer, #view_context

Constructor Details

#initialize(method_name, *args) ⇒ Controller

Instanciate a new TextMessage object.

Then calls method_name with the given args.



33
34
35
36
37
# File 'lib/text_message_rails/controller.rb', line 33

def initialize(method_name, *args)
	@recipients = []
	super()
	process(method_name, *args)
end

Instance Attribute Details

#recipientsObject (readonly)

Basic Recipients handling



40
41
42
# File 'lib/text_message_rails/controller.rb', line 40

def recipients
  @recipients
end

Class Method Details

.default_url_optionsObject

Reuses ActionMailer url options by default



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

def default_url_options
  @@default_url_options || ActionMailer::Base.default_url_options
end

.default_url_options=(options) ⇒ Object



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

def default_url_options=(options)
  @@default_url_options =  options
end

.deliver_text_message(delivery) ⇒ Object



81
82
83
# File 'lib/text_message_rails/controller.rb', line 81

def deliver_text_message(delivery)
  provider.deliver_text_message(delivery)
end

.method_missing(method_name, *args) ⇒ Object

:nodoc:



73
74
75
76
77
78
79
# File 'lib/text_message_rails/controller.rb', line 73

def method_missing(method_name, *args) #:nodoc:
	if action_methods.include?(method_name.to_s)
		TextMessage::Delivery.new(self, method_name, *args)
	else
		super
	end
end

.providerObject

Defaults provider to the Base (empty) provider: will raise !



59
60
61
# File 'lib/text_message_rails/controller.rb', line 59

def provider
  @@provider || TextMessage::Providers::Base
end

.provider=(p) ⇒ Object



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

def provider=(p)
  @@provider = p
end

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

Respond to the action methods directly on the class

for example calling ‘TextMessageDemo.toto` (with TextMessageDemo a subclass of TextMessage::Controller) will create a TextMessage::Delivery instance tied to the `TextMessageDemo` class, method `:toto` with no argument.

Returns:

  • (Boolean)


69
70
71
# File 'lib/text_message_rails/controller.rb', line 69

def respond_to?(method, include_private = false) #:nodoc:
	super || action_methods.include?(method.to_s)
end

Instance Method Details

#send_to(*recipients) ⇒ Object



41
42
43
# File 'lib/text_message_rails/controller.rb', line 41

def send_to(*recipients)
	@recipients = recipients || []
end