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


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

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


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

def client=(client)
  super
  initialize_client
end

#initialize_clientObject

Raises:


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

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].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


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

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

#logger=(logger) ⇒ Object


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

def logger=(logger)
  super(logger)
end

#pid_file=(path) ⇒ Object


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

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

#redis_options=(options) ⇒ Object


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

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

#update(other) ⇒ Object


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

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