Module: Simplepub::Configuration
- Included in:
- Simplepub
- Defined in:
- lib/simplepub/configuration.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #configure {|config| ... } ⇒ Object
- #default_config_file ⇒ Object
- #default_environment ⇒ Object
-
#load_config(filename = default_config_file, environment = default_environment) ⇒ Object
Loads the configuration from a given YAML file and environment (such as production).
-
#reset_config ⇒ Object
Resets the configuration to the default (empty hash).
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/simplepub/configuration.rb', line 6 def config @config end |
Instance Method Details
#configure {|config| ... } ⇒ Object
8 9 10 |
# File 'lib/simplepub/configuration.rb', line 8 def configure(&block) yield(config) end |
#default_config_file ⇒ Object
17 18 19 20 21 |
# File 'lib/simplepub/configuration.rb', line 17 def default_config_file return config.config_file if config.config_file? config_file = config_file_paths.detect { |path| File.exists?(path) } config_file end |
#default_environment ⇒ Object
23 24 25 |
# File 'lib/simplepub/configuration.rb', line 23 def default_environment config.environment? ? config.environment : "development" end |
#load_config(filename = default_config_file, environment = default_environment) ⇒ Object
Loads the configuration from a given YAML file and environment (such as production)
28 29 30 31 32 33 34 35 36 |
# File 'lib/simplepub/configuration.rb', line 28 def load_config(filename=default_config_file, environment=default_environment) raise ConfigurationFileError, "Configuration file not found. Available paths: #{config_file_paths.inspect}" if filename.nil? yaml = YAML.load_file(filename)[environment.to_s] raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil? config.deep_merge!(yaml) end |
#reset_config ⇒ Object
Resets the configuration to the default (empty hash)
13 14 15 |
# File 'lib/simplepub/configuration.rb', line 13 def reset_config @config = Hashie::Mash.new end |