class Smeagol::Config

Server configuration is used to store the options for the Smeagol server for serving sites.

Configuration can be loaded from configuration files located at `/etc/smaegol/config.yml` and `~/.config/smaegol/config.yml` or `~/.smaegol/config.yml`. Here is an example configuration:

Examples

---
port: 3000
auto_update: true
cache_enabled: true
repositories:
  - path: /path/to/wiki/repo
    cname: 'domain.name'
    origin: 'git@github.com:foo/foo.github.com.wiki.git'
    ref: master
    bare: false
    secret: 'pass123'

Constants

CONFIG_HOME

Directory which contains user configuration.

Attributes

auto_update[RW]

While running server, auto-update wiki every day.

base_path[RW]

Serve website via a given base path.

cache[RW]

Use page cache to speed up page requests.

cache_enabled[RW]

Use page cache to speed up page requests.

cache_enabled=[RW]

Use page cache to speed up page requests.

mount_path[RW]

Serve website via a given base path.

mount_path=[RW]

Serve website via a given base path.

port[RW]

Port to use for server. Default is 4567.

repositories[R]

Wiki repository list.

Examples

repositories:
  - path: ~/wikis/banana-blog
  - cname: blog.bananas.org
  - secret: abc123
update[RW]

While running server, auto-update wiki every day.

update=[RW]

While running server, auto-update wiki every day.

Public Class Methods

load(file=nil) click to toggle source

Public: Load Smeagol server configuration.

Returns [Config]

# File lib/smeagol/config.rb, line 32
def self.load(file=nil)
  config = {}

  if file
    config.update(load_config(file))
  else
    config.update(load_config('/etc/smeagol'))
    config.update(load_config("#{CONFIG_HOME}/smeagol", '~/.smeagol'))
  end

  new(config)
end
load_config(*dirs) click to toggle source

Internal: Searches through the given directories looking for `settings.yml` file. Loads and returns the result of the first file found.

dirs - List of directories to search for config file. [Array<String>]

Returns configuration settings or empty Hash if none found. [Hash]

# File lib/smeagol/config.rb, line 52
def self.load_config(*dirs)
  dirs.each do |dir|
    file = File.join(dir, 'config.yml')
    file = File.expand_path(file)
    if File.exist?(file)
      return YAML.load_file(file)
    end
  end
  return {}
end
new(settings={}) click to toggle source

Initialize new Config instance.

# File lib/smeagol/config.rb, line 66
def initialize(settings={})
  @port          = 4567
  @auto_update   = false
  @cache_enabled = true
  @base_path     = ''
  @repositories  = []

  assign(settings)
end

Public Instance Methods

[](name) click to toggle source

Deprecated: Ability to access config like hash.

# File lib/smeagol/config.rb, line 133
def [](name)
  instance_variable_get("@#{name}")
end
assign(settings={}) click to toggle source

Given a Hash of settings, assign via writer methods.

# File lib/smeagol/config.rb, line 79
def assign(settings={})
  settings.each do |k,v|
    __send__("#{k}=", v)
  end
end
repositories=(repos) click to toggle source

Set list of repositories.

# File lib/smeagol/config.rb, line 119
def repositories=(repos)
  @repositories = (
    repos.map do |repo|
      case repo
      when Repository then repo
      else Repository.new(repo) 
      end
    end
  )
end
secret=(secret) click to toggle source

Set secret for all repositories.

# File lib/smeagol/config.rb, line 145
def secret=(secret)
  return if secret.nil?
  repositories.each do |repo|
    repo.secret = secret
  end
end