Class: Phut::Setting

Inherits:
Object
  • Object
show all
Defined in:
lib/phut/setting.rb

Overview

Central configuration repository.

Constant Summary collapse

DEFAULTS =
{
  root: File.expand_path(File.join(File.dirname(__FILE__), '..', '..')),
  logger: Logger.new($stderr).tap do |logger|
            logger.formatter = proc { |_sev, _dtm, _name, msg| msg + "\n" }
            logger.level = Logger::INFO
          end,
  pid_dir: Dir.tmpdir,
  log_dir: Dir.tmpdir,
  socket_dir: Dir.tmpdir
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeSetting

Returns a new instance of Setting.



21
22
23
# File 'lib/phut/setting.rb', line 21

def initialize
  @options = DEFAULTS.dup
end

Instance Method Details

#log_dirObject



46
47
48
# File 'lib/phut/setting.rb', line 46

def log_dir
  @options.fetch :log_dir
end

#log_dir=(path) ⇒ Object



50
51
52
53
# File 'lib/phut/setting.rb', line 50

def log_dir=(path)
  raise "No such directory: #{path}" unless FileTest.directory?(path)
  @options[:log_dir] = File.expand_path(path)
end

#loggerObject



29
30
31
# File 'lib/phut/setting.rb', line 29

def logger
  @options.fetch :logger
end

#logger=(logger) ⇒ Object



33
34
35
# File 'lib/phut/setting.rb', line 33

def logger=(logger)
  @options[:logger] = logger
end

#pid_dirObject



37
38
39
# File 'lib/phut/setting.rb', line 37

def pid_dir
  @options.fetch :pid_dir
end

#pid_dir=(path) ⇒ Object



41
42
43
44
# File 'lib/phut/setting.rb', line 41

def pid_dir=(path)
  raise "No such directory: #{path}" unless FileTest.directory?(path)
  @options[:pid_dir] = File.expand_path(path)
end

#rootObject



25
26
27
# File 'lib/phut/setting.rb', line 25

def root
  @options.fetch :root
end

#socket_dirObject



55
56
57
# File 'lib/phut/setting.rb', line 55

def socket_dir
  @options.fetch :socket_dir
end

#socket_dir=(path) ⇒ Object



59
60
61
62
# File 'lib/phut/setting.rb', line 59

def socket_dir=(path)
  raise "No such directory: #{path}" unless FileTest.directory?(path)
  @options[:socket_dir] = File.expand_path(path)
end