Class: Arcanus::Configuration
- Inherits:
-
Object
- Object
- Arcanus::Configuration
- Defined in:
- lib/arcanus/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.
'config.yaml'.freeze
Class Method Summary collapse
-
.from_file(config_file) ⇒ Arcanus::Configuration
Loads a configuration from a file.
-
.load_applicable(working_directory = Dir.pwd) ⇒ Arcanus::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/arcanus/configuration.rb', line 66 def initialize() @options = end |
Class Method Details
.from_file(config_file) ⇒ Arcanus::Configuration
Loads a configuration from a file.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/arcanus/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(working_directory = Dir.pwd) ⇒ Arcanus::Configuration
Loads appropriate configuration file given the current working directory.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/arcanus/configuration.rb', line 20 def load_applicable(working_directory = Dir.pwd) current_directory = File.(working_directory) config_file = applicable_config_file(current_directory) if config_file from_file(config_file) else # No configuration file, so assume defaults new({}) end end |
Instance Method Details
#==(other) ⇒ true, false
Compares this configuration with another.
90 91 92 |
# File 'lib/arcanus/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/arcanus/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/arcanus/configuration.rb', line 82 def fetch(key, *args) @options.fetch(key.to_s, *args) end |