Class: Daemonic::Configuration
- Inherits:
-
Object
- Object
- Daemonic::Configuration
- Defined in:
- lib/daemonic/configuration.rb
Constant Summary collapse
- Invalid =
Class.new(ArgumentError)
Instance Attribute Summary collapse
-
#eventual_config ⇒ Object
readonly
Returns the value of attribute eventual_config.
-
#given_options ⇒ Object
readonly
Returns the value of attribute given_options.
Instance Method Summary collapse
- #command ⇒ Object
- #config_file ⇒ Object
- #daemonize? ⇒ Boolean
-
#initialize(given_options, pwd) ⇒ Configuration
constructor
A new instance of Configuration.
- #logfile ⇒ Object
- #logger ⇒ Object
- #loglevel ⇒ Object
- #pidfile ⇒ Object
- #program_name ⇒ Object
- #reload ⇒ Object
- #to_h ⇒ Object
- #workers ⇒ Object
- #working_dir ⇒ Object
Constructor Details
#initialize(given_options, pwd) ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 |
# File 'lib/daemonic/configuration.rb', line 11 def initialize(, pwd) @given_options = @pwd = pwd @eventual_config = {} end |
Instance Attribute Details
#eventual_config ⇒ Object (readonly)
Returns the value of attribute eventual_config.
9 10 11 |
# File 'lib/daemonic/configuration.rb', line 9 def eventual_config @eventual_config end |
#given_options ⇒ Object (readonly)
Returns the value of attribute given_options.
9 10 11 |
# File 'lib/daemonic/configuration.rb', line 9 def @given_options end |
Instance Method Details
#command ⇒ Object
17 18 19 |
# File 'lib/daemonic/configuration.rb', line 17 def command self[:command] end |
#config_file ⇒ Object
25 26 27 |
# File 'lib/daemonic/configuration.rb', line 25 def config_file self[:config_file] end |
#daemonize? ⇒ Boolean
21 22 23 |
# File 'lib/daemonic/configuration.rb', line 21 def daemonize? self[:daemonize] end |
#logfile ⇒ Object
56 57 58 |
# File 'lib/daemonic/configuration.rb', line 56 def logfile self[:logfile] || STDOUT end |
#logger ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/daemonic/configuration.rb', line 60 def logger @logger ||= ::Logger.new(logfile).tap { |logger| logger.formatter = proc { |severity, datetime, progname, msg| "[#{severity}] [#{datetime}] [#{program_name}] [#{Process.pid}] #{msg}\n" } logger.level = ::Logger.const_get(loglevel) } end |
#loglevel ⇒ Object
73 74 75 |
# File 'lib/daemonic/configuration.rb', line 73 def loglevel (self[:loglevel] || "INFO").to_s.upcase end |
#pidfile ⇒ Object
52 53 54 |
# File 'lib/daemonic/configuration.rb', line 52 def pidfile self[:pidfile] || File.join(working_dir, "tmp/#{program_name}.pid") end |
#program_name ⇒ Object
48 49 50 |
# File 'lib/daemonic/configuration.rb', line 48 def program_name self[:program_name] || File.basename(working_dir) end |
#reload ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/daemonic/configuration.rb', line 33 def reload @eventual_config = {} @logger = nil defaults if config_file logger.debug { to_h.inspect } validate end |
#to_h ⇒ Object
69 70 71 |
# File 'lib/daemonic/configuration.rb', line 69 def to_h eventual_config end |
#workers ⇒ Object
29 30 31 |
# File 'lib/daemonic/configuration.rb', line 29 def workers Integer(self[:workers] || "1") end |
#working_dir ⇒ Object
44 45 46 |
# File 'lib/daemonic/configuration.rb', line 44 def working_dir self[:working_dir] end |