Class: Smeagol::Config

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

Overview

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:

Constant Summary collapse

CONFIG_HOME =

Directory which contains user configuration.

ENV['XDG_CONFIG_HOME'] || '~/.config'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Config

Initialize new Config instance.


66
67
68
69
70
71
72
73
74
# File 'lib/smeagol/config.rb', line 66

def initialize(settings={})
  @port          = 4567
  @auto_update   = false
  @cache_enabled = true
  @base_path     = ''
  @repositories  = []

  assign(settings)
end

Instance Attribute Details

#auto_updateObject Also known as: update

While running server, auto-update wiki every day.


91
92
93
# File 'lib/smeagol/config.rb', line 91

def auto_update
  @auto_update
end

#base_pathObject Also known as: mount_path

Serve website via a given base path.


101
102
103
# File 'lib/smeagol/config.rb', line 101

def base_path
  @base_path
end

#cacheObject Also known as: cache_enabled

Use page cache to speed up page requests.


96
97
98
# File 'lib/smeagol/config.rb', line 96

def cache
  @cache
end

#portObject

Port to use for server. Default is 4567.


88
89
90
# File 'lib/smeagol/config.rb', line 88

def port
  @port
end

#repositoriesObject

Wiki repository list.

Examples:

repositories:
  - path: ~/wikis/banana-blog
  - cname: blog.bananas.org
  - secret: abc123

114
115
116
# File 'lib/smeagol/config.rb', line 114

def repositories
  @repositories
end

Class Method Details

.load(file = nil) ⇒ Config

Load Smeagol server configuration.

Returns:


32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • dirs

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

Returns:

  • (Hash)

    Returns configuration settings or empty Hash if none found.


52
53
54
55
56
57
58
59
60
61
# 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

Instance Method Details

#[](name) ⇒ Object

Deprecated.

Do not use this in new code, and replace it when updating old code.

Ability to access config like hash.


133
134
135
# File 'lib/smeagol/config.rb', line 133

def [](name)
  instance_variable_get("@#{name}")
end

#assign(settings = {}) ⇒ Object

Given a Hash of settings, assign via writer methods.


79
80
81
82
83
# File 'lib/smeagol/config.rb', line 79

def assign(settings={})
  settings.each do |k,v|
    __send__("#{k}=", v)
  end
end

#secret=(secret) ⇒ Object

Set secret for all repositories.


145
146
147
148
149
150
# File 'lib/smeagol/config.rb', line 145

def secret=(secret)
  return if secret.nil?
  repositories.each do |repo|
    repo.secret = secret
  end
end