module APN::MultipleApps

Attributes

default_app_name[W]

Public Class Methods

extended(mod) click to toggle source
# File lib/apn/multiple_apps.rb, line 5
def self.extended(mod)
  class << mod
    alias_method_chain :notify_sync, :app

    delegate(*Application::DELEGATE_METHODS, to: :current_app, prefix: true, allow_nil: true)

    Application::DELEGATE_METHODS.each do |method_name|
      alias_method :"original_#{method_name}", method_name
      alias_method method_name, :"current_app_#{method_name}"
    end
  end
end

Public Instance Methods

current_app() click to toggle source
# File lib/apn/multiple_apps.rb, line 39
def current_app
  Application::APPS[current_app_name] or \
    raise NameError, "Unregistered APN::Application `#{current_app_name}'"
end
current_app_name() click to toggle source
# File lib/apn/multiple_apps.rb, line 35
def current_app_name
  @_app_name || default_app_name
end
default_app_name() click to toggle source
# File lib/apn/multiple_apps.rb, line 31
def default_app_name
  @default_app_name || 'default'.freeze
end
notify_sync_with_app(token, notification) click to toggle source
# File lib/apn/multiple_apps.rb, line 18
def notify_sync_with_app(token, notification)
  if notification.is_a?(Hash)
    notification.symbolize_keys!
    app_name = notification.delete(:app)
  end

  with_app(app_name) do
    notify_sync_without_app(token, notification)
  end
end
with_app(app_name) { || ... } click to toggle source
# File lib/apn/multiple_apps.rb, line 44
def with_app(app_name)
  @_app_name, app_was = app_name.presence, @_app_name
  yield if block_given?
ensure
  @_app_name = app_was
end