Class: Gerrit::Configuration
- Inherits:
-
Object
- Object
- Gerrit::Configuration
- Defined in:
- lib/gerrit/configuration.rb
Overview
Stores runtime configuration for the application.
This is intended to define helper methods for accessing configuration so this logic can be shared amongst the various components of the system.
Constant Summary collapse
- FILE_NAME =
Name of the configuration file.
'.gerrit.yaml'
Class Method Summary collapse
-
.from_file(config_file) ⇒ Gerrit::Configuration
Loads a configuration from a file.
-
.load_applicable ⇒ Gerrit::Configuration
Loads appropriate configuration file given the current working directory.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compares this configuration with another.
-
#[](key) ⇒ Array, ...
Access the configuration as if it were a hash.
-
#fetch(key, *args) ⇒ Array, ...
Access the configuration as if it were a hash.
-
#initialize(options) ⇒ Configuration
constructor
Creates a configuration from the given options hash.
Constructor Details
#initialize(options) ⇒ Configuration
Creates a configuration from the given options hash.
66 67 68 |
# File 'lib/gerrit/configuration.rb', line 66 def initialize() @options = end |
Class Method Details
.from_file(config_file) ⇒ Gerrit::Configuration
Loads a configuration from a file.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gerrit/configuration.rb', line 35 def from_file(config_file) = if yaml = YAML.load_file(config_file) yaml.to_hash else {} end new() end |
.load_applicable ⇒ Gerrit::Configuration
Loads appropriate configuration file given the current working directory.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gerrit/configuration.rb', line 18 def load_applicable current_directory = File.(Dir.pwd) config_file = applicable_config_file(current_directory) if config_file from_file(config_file) else raise Errors::ConfigurationMissingError, "No configuration file '#{FILE_NAME}' was found in the " \ "current directory or any ancestor directory.\n\n" \ "See #{REPO_URL}#configuration for instructions on setting up." end end |
Instance Method Details
#==(other) ⇒ true, false
Compares this configuration with another.
90 91 92 |
# File 'lib/gerrit/configuration.rb', line 90 def ==(other) super || @options == other.instance_variable_get('@options') end |
#[](key) ⇒ Array, ...
Access the configuration as if it were a hash.
74 75 76 |
# File 'lib/gerrit/configuration.rb', line 74 def [](key) @options[key.to_s] end |
#fetch(key, *args) ⇒ Array, ...
Access the configuration as if it were a hash.
82 83 84 |
# File 'lib/gerrit/configuration.rb', line 82 def fetch(key, *args) @options.fetch(key.to_s, *args) end |