Class: Evertils::Cfg

Inherits:
Object
  • Object
show all
Defined in:
lib/evertils/config.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap!Object

Perform first run tasks and create or read config file values



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/evertils/config.rb', line 4

def bootstrap!
  populate_config

  return if valid_config?

  # no config file found, lets create one using the firstrun controller
  require 'client/controller/firstrun'

  controller = Evertils::Controller::Firstrun.new
  controller.default

  populate_config
end

#get(name) ⇒ Object

Get a specific value from the config file data Params:

name

String/symbol key value



39
40
41
# File 'lib/evertils/config.rb', line 39

def get(name)
  @yml[name.to_sym]
end

#optionsObject

Returns a hash of all module constants and their values



19
20
21
22
23
24
25
# File 'lib/evertils/config.rb', line 19

def options
  keys = Evertils.constants.select { |name| constant?(name) }
  hash = {}

  keys.each { |key| hash[key] = Evertils.const_get(key) }
  hash
end

#populate_configObject

Populates the internal hash which stores any values set in the config file



28
29
30
31
32
33
34
# File 'lib/evertils/config.rb', line 28

def populate_config
  file = File.expand_path("~/.evertils/config.yml")
  fmt = Evertils::Helper.load('Formatting')

  @yml = fmt.symbolize(::YAML.load_file(file))
  self
end