Class: Twigg::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Console
Defined in:
lib/twigg/config.rb

Overview

The Config class mediates all access to the Twigg config file.

First, we look for a YAML file at the location specified by the TWIGGRC environment variable. If that isn’t set, we fallback to looking for a config file at ‘~/.twiggrc`.

Example use:

Config.bind                   # the bind address for the Twigg web app
                              # [default: 0.0.0.0]
Config.gerrit.host            # the (optional) Gerrit hostname
                              # [default: localhost]
Config.gerrit.port            # the (optional) Gerrit port
                              # [default: 29418]
Config.gerrit.user            # the (optional) Gerrit username
                              # [default: $USER environment variable]
Config.repositories_directory # where to find repositories

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(twiggrc: nil) ⇒ Config

Returns a new instance of Config.



58
59
60
61
62
63
# File 'lib/twigg/config.rb', line 58

def initialize(twiggrc: nil)
  @settings = Settings.new(config_from_file(twiggrc) ||
                           config_from_argv ||
                           config_from_env ||
                           config_from_home)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

Foward all messages to the underlying Settings instance.



68
69
70
# File 'lib/twigg/config.rb', line 68

def method_missing(method, *args, &block)
  @settings.send(method, *args, &block)
end

Class Method Details

.bootObject

Perform boot-time configuration



35
36
37
38
# File 'lib/twigg/config.rb', line 35

def boot
  config # ensure `-c`/`--config` option is respected
  set_up_encoding
end