Class: ActionShortMessage::Base
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- ActionShortMessage::Base
show all
- Includes:
- AbstractController::Callbacks, AbstractController::Logger, AbstractController::Rendering, SMSProviders, ActionView::Layouts
- Defined in:
- lib/action_short_message/base.rb
Defined Under Namespace
Classes: NullMessage
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#wrap_sms_provider_behavior!
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
77
78
79
80
81
|
# File 'lib/action_short_message/base.rb', line 77
def initialize
super
@_short_message_was_called = false
@_short_message = ShortMessage.new
end
|
Instance Attribute Details
#template_name ⇒ Object
Returns the value of attribute template_name.
75
76
77
|
# File 'lib/action_short_message/base.rb', line 75
def template_name
@template_name
end
|
#template_path ⇒ Object
Returns the value of attribute template_path.
75
76
77
|
# File 'lib/action_short_message/base.rb', line 75
def template_path
@template_path
end
|
Class Method Details
.base_paths ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/action_short_message/base.rb', line 53
def base_paths
%w[
app/views
app/views/messages
app/views/mailers
app/views/application
app/views/layouts
].freeze
end
|
.default(value = nil) ⇒ Object
Also known as:
default_options=
Sets the defaults through app configuration: config.action_short_message.default()
Aliased by ::default_options=
44
45
46
47
|
# File 'lib/action_short_message/base.rb', line 44
def default(value = nil)
self.default_params = default_params.merge(value).freeze if value
default_params
end
|
.register_observer(observer) ⇒ Object
27
28
29
|
# File 'lib/action_short_message/base.rb', line 27
def register_observer(observer)
Message.register_observer(observer_class_for(observer))
end
|
.register_observers(*observers) ⇒ Object
19
20
21
|
# File 'lib/action_short_message/base.rb', line 19
def register_observers(*observers)
observers.flaten.compact.each { |observer| register_observer(observer) }
end
|
.unrgister_observers(*observers) ⇒ Object
23
24
25
|
# File 'lib/action_short_message/base.rb', line 23
def unrgister_observers(*observers)
observers.flatten.compact.each { |observer| unregister_observer(observer) }
end
|
Instance Method Details
#full_template_path ⇒ Object
121
122
123
|
# File 'lib/action_short_message/base.rb', line 121
def full_template_path
[template_path, template_name].join('/')
end
|
#payload ⇒ Object
83
84
85
|
# File 'lib/action_short_message/base.rb', line 83
def payload
default_options
end
|
#process(method_name, *args) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/action_short_message/base.rb', line 106
def process(method_name, *args)
payload = {
messenger: self.class.name,
action: method_name
}
self.template_path ||= self.class.name.underscore
self.template_name ||= method_name
ActiveSupport::Notifications.instrument('process.action_short_message', payload) do
super
@_short_message = NullMessage.new unless @_short_message_was_called
end
end
|
#sms(params = {}, &block) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/action_short_message/base.rb', line 87
def sms(params = {}, &block)
raise ArgumentError, 'You need to provide at least a receipient' if params[:to].blank?
return short_message if @_short_message_was_called && !block
self.template_name = params[:template_name].presence || template_name
self.template_path = params[:template_path].presence || template_path
@_short_message_was_called = true
wrap_sms_provider_behavior!
short_message.to = params[:to]
short_message.debug = params[:debug]
short_message.message = params[:message] || render(full_template_path)
short_message.options = params.reject! { |p| %i[to debug message].include?(p) }
short_message
end
|