Class: ActionMessageTexter::Base
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- ActionMessageTexter::Base
- Includes:
- AbstractController::Caching, AbstractController::Callbacks, AbstractController::Logger, AbstractController::Translation, DeliveryMethods, Rescuable
- Defined in:
- lib/action_message_texter/base.rb
Overview
所有Texter的父類別
Direct Known Subclasses
Defined Under Namespace
Classes: NullMessage
Class Attribute Summary collapse
Class Method Summary collapse
-
.default(value) ⇒ Object
(also: default_options=)
可在
Texter
中更改設定. -
.deliver_message(message) ⇒ Object
寄送訊息 發出Log Notification.
-
.register_interceptor(interceptor) ⇒ Object
註冊攔截器Interceptor.
-
.register_observer(observer) ⇒ Object
註冊觀察者Observer.
-
.unregister_interceptor(interceptor) ⇒ Object
移除已被註冊的 Interceptor.
-
.unregister_observer(observer) ⇒ Object
移除已被註冊的 Observer.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #process(method_name, *args) ⇒ Object
-
#text(headers = {}) ⇒ Object
return Message instance.
Methods included from DeliveryMethods
Methods included from Rescuable
Constructor Details
Class Attribute Details
.texter_name ⇒ Object
70 71 72 |
# File 'lib/action_message_texter/base.rb', line 70 def texter_name @texter_name ||= anonymous? ? 'anonymous' : name.underscore end |
Class Method Details
.default(value) ⇒ Object Also known as: default_options=
可在 Texter
中更改設定
61 62 63 64 |
# File 'lib/action_message_texter/base.rb', line 61 def default(value) self.default_params = default_params.merge(value).freeze if value default_params end |
.deliver_message(message) ⇒ Object
寄送訊息 發出Log Notification
77 78 79 80 81 82 83 84 85 |
# File 'lib/action_message_texter/base.rb', line 77 def () ActiveSupport::Notifications.instrument('deliver.action_message_texter') do |payload| payload[:content] = .content payload[:to] = .to payload[:deliver_at] = .deliver_at || Time.now payload[:texter] = name yield # Let Message do the delivery actions end end |
.register_interceptor(interceptor) ⇒ Object
註冊攔截器Interceptor
Interceptor
需要包含一個Class Method delivering_message(message) 此Interceptor被註冊後 將於簡訊寄出前觸發delivering_message並取得 message
instance
@params [Class|Symbel|String] interceptor
46 47 48 |
# File 'lib/action_message_texter/base.rb', line 46 def register_interceptor(interceptor) Message.register_interceptor(observer_class_for(interceptor)) end |
.register_observer(observer) ⇒ Object
註冊觀察者Observer
Observer
需要包含一個Class Method delivered_message(message) 此方法會在訊息傳送後被呼叫 並取得 message
instance
29 30 31 |
# File 'lib/action_message_texter/base.rb', line 29 def register_observer(observer) Message.register_observer(observer_class_for(observer)) end |
.unregister_interceptor(interceptor) ⇒ Object
移除已被註冊的 Interceptor
53 54 55 |
# File 'lib/action_message_texter/base.rb', line 53 def unregister_interceptor(interceptor) Message.unregister_observer(observer_class_for(interceptor)) end |
.unregister_observer(observer) ⇒ Object
移除已被註冊的 Observer
36 37 38 |
# File 'lib/action_message_texter/base.rb', line 36 def unregister_observer(observer) Message.unregister_observer(observer_class_for(observer)) end |
Instance Method Details
#process(method_name, *args) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/action_message_texter/base.rb', line 115 def process(method_name, *args) payload = { messenger: self.class.name, action: method_name, args: args } # Notification ActiveSupport::Notifications.instrument('process.action_message_texter', payload) do super @_message = NullMessage.new unless @_message_was_called end end |
#text(headers = {}) ⇒ Object
return Message instance
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/action_message_texter/base.rb', line 133 def text(headers = {}) @_message_was_called = true headers = self.class.default_params.merge(headers) .content = render_content(headers) .to = recipient(headers) .deliver_at = headers.delete(:at) . = headers wrap_delivery_behavior!(self.class.delivery_method) end |