class Pushing::Base

Constants

PROTECTED_IVARS

Attributes

notifier_name[W]

Allows to set the name of current notifier.

Public Class Methods

controller_path()
Alias for: notifier_name
inform_interceptors(notification) click to toggle source
# File lib/pushing/base.rb, line 84
def inform_interceptors(notification)
  delivery_interceptors.each do |interceptor|
    interceptor.delivering_notification(notification)
  end
end
inform_observers(notification, response) click to toggle source
# File lib/pushing/base.rb, line 78
def inform_observers(notification, response)
  delivery_notification_observers.each do |observer|
    observer.delivered_notification(notification, response)
  end
end
notifier_name() click to toggle source
# File lib/pushing/base.rb, line 90
def notifier_name
  @notifier_name ||= anonymous? ? "anonymous" : name.underscore
end
Also aliased as: controller_path
register_interceptor(interceptor) click to toggle source

Register an Interceptor which will be called before notification is sent. Either a class, string or symbol can be passed in as the Interceptor. If a string or symbol is passed in it will be camelized and constantized.

# File lib/pushing/base.rb, line 72
def register_interceptor(interceptor)
  unless delivery_interceptors.include?(interceptor)
    delivery_interceptors << interceptor
  end
end
register_interceptors(*interceptors) click to toggle source

Register one or more Interceptors which will be called before notification is sent.

# File lib/pushing/base.rb, line 56
def register_interceptors(*interceptors)
  interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) }
end
register_observer(observer) click to toggle source

Register an Observer which will be notified when notification is delivered. Either a class, string or symbol can be passed in as the Observer. If a string or symbol is passed in it will be camelized and constantized.

# File lib/pushing/base.rb, line 63
def register_observer(observer)
  unless delivery_notification_observers.include?(observer)
    delivery_notification_observers << observer
  end
end
register_observers(*observers) click to toggle source

Register one or more Observers which will be notified when notification is delivered.

# File lib/pushing/base.rb, line 51
def register_observers(*observers)
  observers.flatten.compact.each { |observer| register_observer(observer) }
end
supports_path?() click to toggle source

Push notifications do not support relative path links.

# File lib/pushing/base.rb, line 106
def supports_path? # :doc:
  false
end

Private Class Methods

method_missing(method_name, *args) click to toggle source
Calls superclass method
# File lib/pushing/base.rb, line 117
def method_missing(method_name, *args)
  if action_methods.include?(method_name.to_s)
    NotificationDelivery.new(self, method_name, *args)
  else
    super
  end
end
respond_to_missing?(method, include_all = false) click to toggle source
Calls superclass method
# File lib/pushing/base.rb, line 125
def respond_to_missing?(method, include_all = false)
  action_methods.include?(method.to_s) || super
end
set_payload_for_notification(payload, notification) click to toggle source
# File lib/pushing/base.rb, line 112
def set_payload_for_notification(payload, notification)
  payload[:notifier]     = name
  payload[:notification] = notification.message.to_h
end

Public Instance Methods

push(headers) click to toggle source
# File lib/pushing/base.rb, line 155
def push(headers)
  return notification if notification && headers.blank?

  payload = {}
  ::Pushing::Platforms.config.select {|platform, _| headers[platform] }.each do |platform, config|
    payload_class = ::Pushing::Platforms.lookup(platform)

    if payload_class.should_render?(headers[platform])
      json = render_json(platform, headers)
      payload[platform] = payload_class.new(json, headers[platform], config)
    end
  end

  # TODO: Do not use OpenStruct
  @_notification = OpenStruct.new(payload)
end

Private Instance Methods

render_json(platform, headers) click to toggle source
# File lib/pushing/base.rb, line 174
def render_json(platform, headers)
  templates_path = headers[:template_path] || self.class.notifier_name
  templates_name = headers[:template_name] || action_name

  lookup_context.variants = platform
  template = lookup_context.find(templates_name, Array(templates_path))

  unless template.instance_variable_get(:@compiled)
    engine  = File.extname(template.identifier).tr!(".", "")
    handler = ::Pushing::TemplateHandlers.lookup(engine)
    template.instance_variable_set(:@handler, handler)
  end

  view_renderer.render_template(view_context, template: template)
end