Class: Configuration

Inherits:
Thor
  • Object
show all
Includes:
Mixin::DefaultConfig, Thor::Actions
Defined in:
lib/fox/interface/thor/configuration.rb

Instance Method Summary collapse

Methods included from Mixin::DefaultConfig

#defaults

Methods included from Mixin::ConfigChoice

#config_choice

Instance Method Details

#cleanObject



57
58
59
# File 'lib/fox/interface/thor/configuration.rb', line 57

def clean
  File.delete(config_path) if File.exist?(config_path)
end

#config(key, value) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fox/interface/thor/configuration.rb', line 36

def config key, value

  Kernel.include Mixin::Configuration

  # othewise load config file if it contain current key change to new value
  current_configuration = YAML.load_file(config_path)

  namaspace = key.split(".")

  abort("Key '#{key}' not found in config") if namaspace.size == 1 || namaspace.size > 2
  abort("Key '#{key}' not found in config") if current_configuration[namaspace.first][namaspace.last].nil?

  current_configuration[namaspace.first][namaspace.last] = value

  File.open(config_path, "w") do |config|
    config.write(current_configuration.to_yaml)
  end

end

#generateObject



26
27
28
29
30
31
# File 'lib/fox/interface/thor/configuration.rb', line 26

def generate
  template_path   = File.expand_path(File.dirname(__FILE__) + '/../../template/config/config.tt') 
  source_paths    << template_path
  config          = defaults['fox'].merge(options)
  template(template_path, config_path, config)
end