Class: Smeagol::Config
- Inherits:
-
Object
- Object
- Smeagol::Config
- 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
-
#auto_update ⇒ Object
(also: #update)
While running server, auto-update wiki every day.
-
#base_path ⇒ Object
(also: #mount_path)
Serve website via a given base path.
-
#cache ⇒ Object
(also: #cache_enabled)
Use page cache to speed up page requests.
-
#port ⇒ Object
Port to use for server.
-
#repositories ⇒ Object
Wiki repository list.
Class Method Summary collapse
-
.load(file = nil) ⇒ Config
Load Smeagol server configuration.
-
.load_config(*dirs) ⇒ Hash
private
Searches through the given directories looking for ‘settings.yml` file.
Instance Method Summary collapse
-
#[](name) ⇒ Object
deprecated
Deprecated.
Do not use this in new code, and replace it when updating old code.
-
#assign(settings = {}) ⇒ Object
Given a Hash of settings, assign via writer methods.
-
#initialize(settings = {}) ⇒ Config
constructor
Initialize new Config instance.
-
#secret=(secret) ⇒ Object
Set secret for all repositories.
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_update ⇒ Object 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_path ⇒ Object 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 |
#cache ⇒ Object 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 |
#port ⇒ Object
Port to use for server. Default is 4567.
88 89 90 |
# File 'lib/smeagol/config.rb', line 88 def port @port end |
#repositories ⇒ Object
Wiki repository list.
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.
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.
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.(file) if File.exist?(file) return YAML.load_file(file) end end return {} end |
Instance Method Details
#[](name) ⇒ Object
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 |