Class: Hummingbird::Configuration
- Inherits:
-
Object
- Object
- Hummingbird::Configuration
- 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
-
#basedir ⇒ String
The directory on which to base relative paths of other settings.
-
#connection_string ⇒ String
The / Sequel compatible connection string.
-
#initialize(config_dir, opts = {}) ⇒ Configuration
constructor
Provides access to the settings found in the configuration file, and user specific configuration file.
-
#migrations_dir ⇒ String
The base directory for all migration files.
-
#migrations_table ⇒ Symbol
The name of the migrations table used to keep track of which migrations have been successfully run, and when they were run.
-
#planfile ⇒ String
The file containing the list of migrations to be run in the order that they should be run.
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.
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.(f,config_dir) end @config_dir = config_dir @config = Optimism.require(*config_file_names) end |
Instance Method Details
#basedir ⇒ String
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).
71 72 73 |
# File 'lib/hummingbird/configuration.rb', line 71 def basedir @basedir ||= File.(@config[:basedir] || '.', @config_dir) end |
#connection_string ⇒ String
The / Sequel compatible connection string. This has no default, and must be specified in the configuration file, or provided by another means.
113 114 115 |
# File 'lib/hummingbird/configuration.rb', line 113 def connection_string @connection_string ||= @config[:connection_string] end |
#migrations_dir ⇒ String
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`.
94 95 96 |
# File 'lib/hummingbird/configuration.rb', line 94 def migrations_dir @migrations_dir ||= File.(@config[:migrations_dir] || 'migrations', basedir) end |
#migrations_table ⇒ Symbol
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`.
103 104 105 |
# File 'lib/hummingbird/configuration.rb', line 103 def migrations_table @migrations_table ||= (@config[:migrations_table] || :hummingbird_migrations).to_sym end |
#planfile ⇒ String
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`.
83 84 85 |
# File 'lib/hummingbird/configuration.rb', line 83 def planfile @planfile ||= File.(@config[:planfile] || 'hummingbird.plan', basedir) end |