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/#{ChefUtils::Dist::Infra::SHORT}-backup",
    "project_name" => ChefUtils::Dist::Org::LEGACY_CONF_DIR,
    "ctl-command" => ChefUtils::Dist::Server::SERVER_CTL,
    "running_filepath" => "/etc/#{ChefUtils::Dist::Org::LEGACY_CONF_DIR}/#{ChefUtils::Dist::Server::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



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

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



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

def [](key)
  config[key]
end

.[]=(key, value) ⇒ Object



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

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

.configObject



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

def config
  @config ||= new
end

.config=(hash) ⇒ Object



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

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

.from_json_file(file) ⇒ Object

Parameters:

  • file (String)

    path to a JSON configration file



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

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



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

def to_hash
  @config
end