Class: ActionPush::Base
- Inherits:
-
Object
- Object
- ActionPush::Base
- Extended by:
- Concerns::ClassMethodDelivery, Concerns::RegisterDefault, Concerns::RegisterDeliveryMethod, Concerns::RegisterInterceptor
- Defined in:
- lib/action_push/base.rb
Constant Summary
Constants included from Concerns::RegisterInterceptor
Concerns::RegisterInterceptor::DEFAULT_INTERCEPTOR
Instance Attribute Summary collapse
-
#action_name ⇒ Object
Returns the value of attribute action_name.
Class Method Summary collapse
Instance Method Summary collapse
- #envelope ⇒ Object
- #i18n_scope ⇒ Object
-
#initialize(action_name: nil) ⇒ Base
constructor
A new instance of Base.
- #push(provider, attributes = {}) {|push| ... } ⇒ Provider::Envelope
- #translate(key, options = {}) ⇒ Object (also: #t)
Methods included from Concerns::ClassMethodDelivery
action_methods, method_missing, respond_to_missing?
Methods included from Concerns::RegisterDefault
default, defaults, register_default
Methods included from Concerns::RegisterDeliveryMethod
delivery_methods, register_delivery_method
Methods included from Concerns::RegisterInterceptor
interceptor, register_interceptor
Constructor Details
#initialize(action_name: nil) ⇒ Base
Returns a new instance of Base.
28 29 30 |
# File 'lib/action_push/base.rb', line 28 def initialize(action_name: nil) @action_name = action_name end |
Instance Attribute Details
#action_name ⇒ Object
Returns the value of attribute action_name.
12 13 14 |
# File 'lib/action_push/base.rb', line 12 def action_name @action_name end |
Class Method Details
.inherited(subclass) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/action_push/base.rb', line 14 def self.inherited(subclass) super subclass.register_interceptor(interceptor) defaults.each do |name, placeholder| subclass.register_default(name, placeholder.clone) end delivery_methods.each do |name, handler| subclass.register_delivery_method(name, handler) end end |
Instance Method Details
#envelope ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/action_push/base.rb', line 32 def envelope @envelope ||= Envelope.new do |env| self.class.defaults.each do |name, placeholder| env.add(name, placeholder.dup) end end end |
#i18n_scope ⇒ Object
61 62 63 |
# File 'lib/action_push/base.rb', line 61 def i18n_scope "#{Util.underscore(self.class.to_s)}.#{action_name}" end |
#push(provider, attributes = {}) {|push| ... } ⇒ Provider::Envelope
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/action_push/base.rb', line 41 def push(provider, attributes = {}) push = envelope.for(provider) push.title = envelope.title if envelope.title push.body = envelope.body if envelope.body push.payload = envelope.payload if envelope.payload push.scheduled = true push.delivery_method = self.class.delivery_methods.fetch(provider, Delivery::Explosion) # after all push.assign(attributes) yield(push) if block_given? envelope end |
#translate(key, options = {}) ⇒ Object Also known as: t
57 58 59 |
# File 'lib/action_push/base.rb', line 57 def translate(key, = {}) I18n.translate(key, { scope: i18n_scope }.merge()) end |