Class: Stove::Config
- Inherits:
-
Object
- Object
- Stove::Config
- Includes:
- Logify, Mixin::Instanceable
- Defined in:
- lib/stove/config.rb
Instance Method Summary collapse
-
#__path__ ⇒ String
This is a special key that tells me where stove lives.
-
#initialize ⇒ Config
constructor
Create a new configuration object.
-
#method_missing(m, *args, &block) ⇒ Object
Deletegate all method calls to the underlyng hash.
Methods included from Mixin::Instanceable
Constructor Details
#initialize ⇒ Config
Create a new configuration object. If a configuration file does not exist, this method will output a warning to the UI and use an empty hash as the data structure.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stove/config.rb', line 13 def initialize log.debug("Reading from config at `#{__path__}'") contents = File.read(__path__) data = JSON.parse(contents, symbolize_names: true) log.debug("Config:\n#{JSON.pretty_generate(sanitize(data))}") @data = data rescue Errno::ENOENT log.warn(" No Stove configuration file found at `\#{__path__}'. Stove will assume an\n empty configuration, which may cause problems with some plugins. It is\n recommended that you create a Stove configuration file as documented:\n\n https://github.com/sethvargo/stove#installation\n EOH\n\n @data = {}\nend\n".gsub(/^ {8}/, '')) |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Deletegate all method calls to the underlyng hash.
47 48 49 |
# File 'lib/stove/config.rb', line 47 def method_missing(m, *args, &block) @data.send(m, *args, &block) end |
Instance Method Details
#__path__ ⇒ String
This is a special key that tells me where stove lives. If you actually have a key in your config called __path__, then it sucks to be you.
40 41 42 |
# File 'lib/stove/config.rb', line 40 def __path__ @path ||= File.(ENV['STOVE_CONFIG'] || '~/.stove') end |