Class: DaemonKit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/daemon_kit/initializer.rb

Overview

Holds our various configuration values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/daemon_kit/initializer.rb', line 169

def initialize
  set_root_path!
  
  self.load_paths = default_load_paths
  self.log_level  = default_log_level
  self.log_path   = default_log_path

  self.multiple = false
  self.force_kill_wait = false

  @signal_traps = {}
end

Instance Attribute Details

#daemon_nameObject

The application name



158
159
160
# File 'lib/daemon_kit/initializer.rb', line 158

def daemon_name
  @daemon_name
end

#dirObject

Path to the log file, defaults to ‘log/<environment>.log’



152
153
154
# File 'lib/daemon_kit/initializer.rb', line 152

def dir
  @dir
end

#dir_modeObject

:system,



149
150
151
# File 'lib/daemon_kit/initializer.rb', line 149

def dir_mode
  @dir_mode
end

#force_kill_waitObject

Use the force kill patch? Give the number of seconds



164
165
166
# File 'lib/daemon_kit/initializer.rb', line 164

def force_kill_wait
  @force_kill_wait
end

#load_pathsObject

List of load paths



140
141
142
# File 'lib/daemon_kit/initializer.rb', line 140

def load_paths
  @load_paths
end

#log_levelObject

The log level to use, defaults to DEBUG



143
144
145
# File 'lib/daemon_kit/initializer.rb', line 143

def log_level
  @log_level
end

#log_pathObject

Path to the log file, defaults to ‘log/<environment>.log’



146
147
148
# File 'lib/daemon_kit/initializer.rb', line 146

def log_path
  @log_path
end

#loggerObject

Provide a custom logger to use



155
156
157
# File 'lib/daemon_kit/initializer.rb', line 155

def logger
  @logger
end

#multipleObject

Allow multiple copies to run?



161
162
163
# File 'lib/daemon_kit/initializer.rb', line 161

def multiple
  @multiple
end

#root_pathObject (readonly)

Root to the daemon



137
138
139
# File 'lib/daemon_kit/initializer.rb', line 137

def root_path
  @root_path
end

#signal_trapsObject (readonly)

Collection of signal traps



167
168
169
# File 'lib/daemon_kit/initializer.rb', line 167

def signal_traps
  @signal_traps
end

Instance Method Details

#daemon_initializerObject



192
193
194
# File 'lib/daemon_kit/initializer.rb', line 192

def daemon_initializer
  "#{root_path}/config/initializers/#{self.daemon_name}.rb"
end

#environmentObject



182
183
184
# File 'lib/daemon_kit/initializer.rb', line 182

def environment
  ::DAEMON_ENV
end

#environment_pathObject

The path to the current environment’s file (development.rb, etc.). By default the file is at config/environments/#{environment}.rb.



188
189
190
# File 'lib/daemon_kit/initializer.rb', line 188

def environment_path
  "#{root_path}/config/environments/#{environment}.rb"
end

#trap(signal, proc = nil, &block) ⇒ Object

Add a trap for the specified signal, can be code block or a proc



197
198
199
200
201
202
203
204
205
# File 'lib/daemon_kit/initializer.rb', line 197

def trap( signal, proc = nil, &block )
  return if proc.nil? && !block_given?
  
  unless @signal_traps.has_key?( signal )
    set_trap( signal )
  end
  
  @signal_traps[signal].unshift( proc || block )
end