Class: ChefBackup::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chef_backup/config.rb

Overview

ChefBackup Global Config

Constant Summary collapse

DEFAULT_BASE =
"private_chef".freeze
DEFAULT_CONFIG =
{
  "backup" => {
    "always_dump_db" => true,
    "strategy" => "none",
    "export_dir" => "/var/opt/chef-backup",
    "project_name" => "opscode",
    "ctl-command" => "chef-server-ctl",
    "running_filepath" => "/etc/opscode/chef-server-running.json",
    "database_name" => "opscode_chef",
  },
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Config

Returns a new instance of Config.

Parameters:

  • config (Hash) (defaults to: {})

    a Hash of the private-chef-running.json



52
53
54
55
56
57
58
59
# File 'lib/chef_backup/config.rb', line 52

def initialize(config = {})
  config["config_base"] ||= DEFAULT_BASE
  base = config["config_base"]
  config[base] ||= {}
  config[base]["backup"] ||= {}
  config[base]["backup"] = DEFAULT_CONFIG["backup"].merge(config[base]["backup"])
  @config = config
end

Class Method Details

.[](key) ⇒ Object



32
33
34
# File 'lib/chef_backup/config.rb', line 32

def [](key)
  config[key]
end

.[]=(key, value) ⇒ Object



36
37
38
# File 'lib/chef_backup/config.rb', line 36

def []=(key, value)
  config[key] = value
end

.configObject



24
25
26
# File 'lib/chef_backup/config.rb', line 24

def config
  @config ||= new
end

.config=(hash) ⇒ Object



28
29
30
# File 'lib/chef_backup/config.rb', line 28

def config=(hash)
  @config = new(hash)
end

.from_json_file(file) ⇒ Object

Parameters:

  • file (String)

    path to a JSON configration file



43
44
45
46
# File 'lib/chef_backup/config.rb', line 43

def from_json_file(file)
  path = File.expand_path(file)
  @config = new(JSON.parse(File.read(path))) if File.exist?(path)
end

Instance Method Details

#to_hashObject



61
62
63
# File 'lib/chef_backup/config.rb', line 61

def to_hash
  @config
end