Module: APN::MultipleApps

Included in:
APN
Defined in:
lib/apn/multiple_apps.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_app_nameObject



31
32
33
# File 'lib/apn/multiple_apps.rb', line 31

def default_app_name
  @default_app_name || 'default'.freeze
end

Class Method Details

.extended(mod) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# 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

Instance Method Details

#current_appObject



39
40
41
42
# 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_nameObject



35
36
37
# File 'lib/apn/multiple_apps.rb', line 35

def current_app_name
  @_app_name || default_app_name
end

#notify_sync_with_app(token, notification) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# 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) ⇒ Object



44
45
46
47
48
49
# 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