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, *params) ⇒ Controller

Instanciate a new TextMessage object.

Then calls method_name with the given args.



35
36
37
38
39
40
# File 'lib/text_message_rails/controller.rb', line 35

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



30
31
32
# File 'lib/text_message_rails/controller.rb', line 30

def params
  @params
end

#recipientsObject (readonly)

Basic Recipients handling



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

def recipients
  @recipients
end

Class Method Details

.default_url_optionsObject

Reuses ActionMailer url options by default



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

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

.default_url_options=(options) ⇒ Object



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

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

.deliver_text_message(delivery) ⇒ Object



88
89
90
# File 'lib/text_message_rails/controller.rb', line 88

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

.method_missing(method_name, *args) ⇒ Object

:nodoc:



80
81
82
83
84
85
86
# File 'lib/text_message_rails/controller.rb', line 80

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 !



66
67
68
# File 'lib/text_message_rails/controller.rb', line 66

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

.provider=(p) ⇒ Object



62
63
64
# File 'lib/text_message_rails/controller.rb', line 62

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)


76
77
78
# File 'lib/text_message_rails/controller.rb', line 76

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

Instance Method Details

#deliveryObject



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

def delivery
  TextMessage::Delivery.new(self, action_name, *params)
end

#send_to(*recipients) ⇒ Object



44
45
46
# File 'lib/text_message_rails/controller.rb', line 44

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