Class: AppConfig::Storage::YAML
- Defined in:
- lib/app_config/storage/yaml.rb
Overview
YAML storage method.
Constant Summary collapse
- DEFAULT_PATH =
File.join(Dir.home, '.app_config.yml')
Instance Method Summary collapse
-
#initialize(path = DEFAULT_PATH, options = {}) ⇒ YAML
constructor
Loads ‘@data` with the YAML file located at `path`.
- #reload! ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path = DEFAULT_PATH, options = {}) ⇒ YAML
Loads ‘@data` with the YAML file located at `path`. `@data` will be the OpenStruct that is accessed with `AppConfig.some_var`.
Defaults to ‘Dir.home/.app_config.yml`
15 16 17 18 19 20 |
# File 'lib/app_config/storage/yaml.rb', line 15 def initialize(path = DEFAULT_PATH, = {}) # Allow passing `true` as an option to use `DEFAULT_PATH`. @path = path.is_a?(TrueClass) ? DEFAULT_PATH : path = reload! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AppConfig::Storage::Base
Instance Method Details
#reload! ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/app_config/storage/yaml.rb', line 22 def reload! # Make sure to use the top-level YAML module here. if .has_key?(:env) env = [:env].to_s # Force a String here since YAML's keys are strings. @data = Storage::ConfigData.new(::YAML.load_file(@path)[env]) else @data = Storage::ConfigData.new(::YAML.load_file(@path)) end end |