Class: Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/librr/settings.rb

Constant Summary collapse

CONFIG_PATH =
File.expand_path('~/.librr/')
CONFIG_FILE =
self.in_dir('config')
PID_FILE =
self.in_dir('server.pid')
DEFAULTS =
{
  runner_port: 4512,
  config_path: CONFIG_PATH,
  escape_files: /[#~]$|^[\.#]/,
  solr_port: 8901,
}

Class Method Summary collapse

Class Method Details

.in_dir(filename) ⇒ Object



7
8
9
# File 'lib/librr/settings.rb', line 7

def self.in_dir(filename)
  File.join(CONFIG_PATH, filename)
end

.method_missing(name) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/librr/settings.rb', line 35

def self.method_missing(name)
  self.reload unless defined?(@@config)

  if @@config.include?(name)
    @@config[name]
  else
    super
  end
end

.reloadObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/librr/settings.rb', line 22

def self.reload
  if File.exists?(CONFIG_FILE)
    begin
      @@config = YAML.load File.read(CONFIG_FILE)
      raise unless @@config.kind_of?(Hash)
    rescue
      raise "config file format error: #{CONFIG_FILE}"
    end
  else
    @@config = DEFAULTS.dup
  end
end