Class: Hummingbird::Configuration

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

Overview

Helper class to handle reading configuration options from YAML files.

Constant Summary collapse

CONFIG_FILE =

The name of the default configuration file.

'hummingbird.yml'
USER_CONFIG_FILE =

The name of the default user specific configuration file. Used for overriding settings in the default configuration file, or providing values for settings missing from there.

'.hummingbird.yml'

Instance Method Summary collapse

Constructor Details

#initialize(config_dir, opts = {}) ⇒ Configuration

Provides access to the settings found in the configuration file, and user specific configuration file. By default it will look for CONFIG_FILE, and USER_CONFIG_FILE in the specified ‘config_dir`. These can be overridden.

The YAML configuration files should be in the format:

---
basedir: 'sql'
planfile: 'application.plan'
migrations_dir: 'migrations-dir'
migrations_table: 'application_migrations'
connection_string: 'sequel connection string'

See the individual access methods for details about each setting.

Parameters:

  • config_dir (String)

    The directory in which to look for configuration files.

  • opts (Hash) (defaults to: {})

    Overrides for the default configuration file names and locations.

Options Hash (opts):

  • :config_file (String)

    Override the default configuration file name and location. This can be either a path relative to the ‘config_dir`, or an absolute path to the configuration file.

  • :user_config_file (String)

    Override the default user specific configuration file name and location. This can be either a path relative to the ‘config_dir`, or an absolute path to the configuration file.

See Also:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hummingbird/configuration.rb', line 52

def initialize(config_dir,opts={})
  opts[:config_file]      ||= CONFIG_FILE
  opts[:user_config_file] ||= USER_CONFIG_FILE

  config_file_names = [opts[:config_file],opts[:user_config_file]].map do |f|
    File.expand_path(f,config_dir)
  end

  @config_dir = config_dir
  @config = Optimism.require(*config_file_names)
end

Instance Method Details

#basedirString

The directory on which to base relative paths of other settings. This directory itself is relative to ‘Dir.getwd` unless specified as an absolute path. This defaults to ’.‘ (the current working directory).

Returns:

  • (String)

    The absolute path to the directory specified in the config file.



71
72
73
# File 'lib/hummingbird/configuration.rb', line 71

def basedir
  @basedir ||= File.expand_path(@config[:basedir] || '.', @config_dir)
end

#connection_stringString

The / Sequel compatible connection string. This has no default, and must be specified in the configuration file, or provided by another means.

Returns:

  • (String)

    Connection string to be passed to / Sequel.



113
114
115
# File 'lib/hummingbird/configuration.rb', line 113

def connection_string
  @connection_string ||= @config[:connection_string]
end

#migrations_dirString

The base directory for all migration files. This is relative to #basedir when specified in the configuration file, unless specified as an absolute path. Defaults to ‘migrations`.

Returns:

  • (String)

    The absolute path to the plan file.

See Also:



94
95
96
# File 'lib/hummingbird/configuration.rb', line 94

def migrations_dir
  @migrations_dir ||= File.expand_path(@config[:migrations_dir] || 'migrations', basedir)
end

#migrations_tableSymbol

The name of the migrations table used to keep track of which migrations have been successfully run, and when they were run. Defaults to ‘hummingbird_migrations`.

Returns:

  • (Symbol)

    The name of the migrations table as a symbol.



103
104
105
# File 'lib/hummingbird/configuration.rb', line 103

def migrations_table
  @migrations_table ||= (@config[:migrations_table] || :hummingbird_migrations).to_sym
end

#planfileString

The file containing the list of migrations to be run in the order that they should be run. This is relative to #basedir when specified in the configuration file, unless specified as an absolute path. Defaults to ‘hummingbird.plan`.

Returns:

  • (String)

    The absolute path to the plan file.

See Also:



83
84
85
# File 'lib/hummingbird/configuration.rb', line 83

def planfile
  @planfile ||= File.expand_path(@config[:planfile] || 'hummingbird.plan', basedir)
end