Class: WebVac::Config

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

Overview

Config object, intended to be used as a singleton.

Constant Summary collapse

Defaults =

The default config options. See the README.

{
  redis_url: "redis://localhost:6379/0",

  server_path_strip: "/media",
  server_path_prepend: "/media/block/fse",

  venti_server: 'localhost',

  plan9bin: '/opt/plan9/bin',

  mime_substitutions: {
    'text/html' => 'text/plain',
  },
}
ConfigPaths =

The sorted list of places where we will look for config files to load.

[
  ENV['WEBVAC_CONFIG'],
  "./config/webvac.json",
  "#{ENV['HOME']}/.webvac.json",
  "/etc/webvac.json",
].compact

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Config

Takes a config, replaces the defaults with it. Will throw exceptions if you give it a bad config, you should probably just call Config.load.



53
54
55
56
57
58
59
60
# File 'lib/webvac.rb', line 53

def initialize cfg
  Defaults.each { |k,v|
    send("#{k}=", v)
  }
  cfg.each { |k,v|
    send("#{k}=", v)
  }
end

Class Method Details

.loadObject

Reads/parses config and instantiates an object



40
41
42
43
44
45
46
47
48
# File 'lib/webvac.rb', line 40

def self.load
  f = ConfigPaths.find { |f| File.readable?(f) }
  cfg = if f
    JSON.parse File.read(f)
  else
    {}
  end
  new cfg
end

Instance Method Details

#path_fixup(path) ⇒ Object



62
63
64
65
# File 'lib/webvac.rb', line 62

def path_fixup path
  @_path_rx ||= /^#{Regexp.escape(server_path_strip)}/
  path.sub(@_path_rx, server_path_prepend)
end