Class: Rpush::Configuration

Inherits:
Struct
  • Object
show all
Includes:
Deprecatable
Defined in:
lib/rpush/configuration.rb

Overview

rubocop:disable Style/StructInheritance

Instance Method Summary collapse

Methods included from Deprecatable

included

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rpush/configuration.rb', line 45

def initialize
  super

  self.push_poll = 2
  self.batch_size = 100
  self.logger = nil
  self.log_file = 'log/rpush.log'
  self.pid_file = 'tmp/rpush.pid'
  self.log_level = (defined?(Rails) && Rails.logger) ? Rails.logger.level : ::Logger::Severity::DEBUG
  self.plugin = OpenStruct.new
  self.foreground = false

  self.apns = ApnsConfiguration.new

  # Internal options.
  self.embedded = false
  self.push = false
end

Instance Method Details

#client=(client) ⇒ Object



91
92
93
94
# File 'lib/rpush/configuration.rb', line 91

def client=(client)
  super
  initialize_client
end

#initialize_clientObject

Raises:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rpush/configuration.rb', line 100

def initialize_client
  return if @client_initialized
  raise ConfigurationError, 'Rpush.config.client is not set.' unless client
  require "rpush/client/#{client}"

  client_module = Rpush::Client.const_get(client.to_s.camelize)
  Rpush.send(:include, client_module) unless Rpush.ancestors.include?(client_module)

  [:Apns, :Gcm, :Wpns, :Wns, :Adm, :Pushy].each do |service|
    Rpush.const_set(service, client_module.const_get(service)) unless Rpush.const_defined?(service)
  end

  @client_initialized = true
end

#log_file=(path) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/rpush/configuration.rb', line 79

def log_file=(path)
  if path && !Pathname.new(path).absolute?
    super(File.join(Rpush.root, path))
  else
    super
  end
end

#logger=(logger) ⇒ Object



87
88
89
# File 'lib/rpush/configuration.rb', line 87

def logger=(logger)
  super(logger)
end

#pid_file=(path) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/rpush/configuration.rb', line 71

def pid_file=(path)
  if path && !Pathname.new(path).absolute?
    super(File.join(Rpush.root, path))
  else
    super
  end
end

#redis_options=(options) ⇒ Object



96
97
98
# File 'lib/rpush/configuration.rb', line 96

def redis_options=(options)
  Modis.redis_options = options if client == :redis
end

#update(other) ⇒ Object



64
65
66
67
68
69
# File 'lib/rpush/configuration.rb', line 64

def update(other)
  CONFIG_ATTRS.each do |attr|
    other_value = other.send(attr)
    send("#{attr}=", other_value) unless other_value.nil?
  end
end