Module: Rpush::Daemon::ServiceConfigMethods

Included in:
Adm, Apns, Apns2, Gcm, Wns, Wpns
Defined in:
lib/rpush/daemon/service_config_methods.rb

Constant Summary collapse

DISPATCHERS =
{
  http:       Rpush::Daemon::Dispatcher::Http,
  tcp:        Rpush::Daemon::Dispatcher::Tcp,
  apns_tcp:   Rpush::Daemon::Dispatcher::ApnsTcp,
  apns_http2: Rpush::Daemon::Dispatcher::ApnsHttp2
}

Instance Method Summary collapse

Instance Method Details

#batch_deliveries(value = nil) ⇒ Object



11
12
13
14
# File 'lib/rpush/daemon/service_config_methods.rb', line 11

def batch_deliveries(value = nil)
  return batch_deliveries? if value.nil?
  @batch_deliveries = value
end

#batch_deliveries?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rpush/daemon/service_config_methods.rb', line 16

def batch_deliveries?
  @batch_deliveries == true
end

#delivery_classObject



29
30
31
# File 'lib/rpush/daemon/service_config_methods.rb', line 29

def delivery_class
  const_get('Delivery')
end

#dispatcher(name = nil, options = {}) ⇒ Object



20
21
22
23
# File 'lib/rpush/daemon/service_config_methods.rb', line 20

def dispatcher(name = nil, options = {})
  @dispatcher_name = name
  @dispatcher_options = options
end

#dispatcher_classObject



25
26
27
# File 'lib/rpush/daemon/service_config_methods.rb', line 25

def dispatcher_class
  DISPATCHERS[@dispatcher_name] || (fail NotImplementedError)
end

#loop_instances(app) ⇒ Object



42
43
44
45
46
47
# File 'lib/rpush/daemon/service_config_methods.rb', line 42

def loop_instances(app)
  (@loops || []).map do |cls, options|
    next unless options.key?(:if) ? options[:if].call : true
    cls.new(app)
  end.compact
end

#loops(classes, options = {}) ⇒ Object



37
38
39
40
# File 'lib/rpush/daemon/service_config_methods.rb', line 37

def loops(classes, options = {})
  classes = Array[*classes]
  @loops = classes.map { |cls| [cls, options] }
end

#new_dispatcher(app) ⇒ Object



33
34
35
# File 'lib/rpush/daemon/service_config_methods.rb', line 33

def new_dispatcher(app)
  dispatcher_class.new(app, delivery_class, @dispatcher_options)
end