Class: Stove::Config

Inherits:
Object
  • Object
show all
Includes:
Logify, Mixin::Instanceable
Defined in:
lib/stove/config.rb

Instance Method Summary collapse

Methods included from Mixin::Instanceable

extended, included

Constructor Details

#initializeConfig

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.

Returns:

  • (String)


40
41
42
# File 'lib/stove/config.rb', line 40

def __path__
  @path ||= File.expand_path(ENV['STOVE_CONFIG'] || '~/.stove')
end