Class: ActionPush::Base
- Inherits:
-
Object
- Object
- ActionPush::Base
- Extended by:
- Concerns::ClassMethodDelivery, Concerns::RegisterDefault, Concerns::RegisterDeliveryMethod
- Defined in:
- lib/action_push/base.rb
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
Constructor Details
#initialize(action_name: nil) ⇒ Base
Returns a new instance of Base.
25 26 27 |
# File 'lib/action_push/base.rb', line 25 def initialize(action_name: nil) @action_name = action_name end |
Instance Attribute Details
#action_name ⇒ Object
Returns the value of attribute action_name.
11 12 13 |
# File 'lib/action_push/base.rb', line 11 def action_name @action_name end |
Class Method Details
.inherited(subclass) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_push/base.rb', line 13 def self.inherited(subclass) super 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
29 30 31 32 33 34 35 |
# File 'lib/action_push/base.rb', line 29 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
58 59 60 |
# File 'lib/action_push/base.rb', line 58 def i18n_scope "#{Util.underscore(self.class.to_s)}.#{action_name}" end |
#push(provider, attributes = {}) {|push| ... } ⇒ Provider::Envelope
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/action_push/base.rb', line 38 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
54 55 56 |
# File 'lib/action_push/base.rb', line 54 def translate(key, = {}) I18n.translate(key, { scope: i18n_scope }.merge()) end |