Module: Backup::Config

Extended by:
Utilities::Helpers
Defined in:
lib/backup/config.rb,
lib/backup/config/dsl.rb,
lib/backup/config/helpers.rb

Defined Under Namespace

Modules: Helpers Classes: DSL, Defaults, Error

Constant Summary collapse

DEFAULTS =
{
  :config_file  => 'config.rb',
  :data_path    => '.data',
  :tmp_path     => '.tmp'
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config_fileObject (readonly)

Returns the value of attribute config_file.



18
19
20
# File 'lib/backup/config.rb', line 18

def config_file
  @config_file
end

.data_pathObject (readonly)

Returns the value of attribute data_path.



18
19
20
# File 'lib/backup/config.rb', line 18

def data_path
  @data_path
end

.root_pathObject (readonly)

Returns the value of attribute root_path.



18
19
20
# File 'lib/backup/config.rb', line 18

def root_path
  @root_path
end

.tmp_pathObject (readonly)

Returns the value of attribute tmp_path.



18
19
20
# File 'lib/backup/config.rb', line 18

def tmp_path
  @tmp_path
end

.userObject (readonly)

Returns the value of attribute user.



18
19
20
# File 'lib/backup/config.rb', line 18

def user
  @user
end

Class Method Details

.hostnameObject



52
53
54
# File 'lib/backup/config.rb', line 52

def hostname
  @hostname ||= run(utility(:hostname))
end

.load(options = {}) ⇒ Object

Loads the user’s config.rb and all model files.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/backup/config.rb', line 21

def load(options = {})
  update(options)  # from the command line

  unless File.exist?(config_file)
    raise Error, "Could not find configuration file: '#{config_file}'."
  end

  config = File.read(config_file)
  version = Backup::VERSION.split('.').first
  unless config =~ /^# Backup v#{ version }\.x Configuration$/
    raise Error, <<-EOS
      Invalid Configuration File
      The configuration file at '#{ config_file }'
      does not appear to be a Backup v#{ version }.x configuration file.
      If you have upgraded to v#{ version }.x from a previous version,
      you need to upgrade your configuration file.
      Please see the instructions for upgrading in the Backup documentation.
    EOS
  end

  dsl = DSL.new
  dsl.instance_eval(config, config_file)

  update(dsl._config_options)  # from config.rb
  update(options)              # command line takes precedence

  Dir[File.join(File.dirname(config_file), 'models', '*.rb')].each do |model|
    dsl.instance_eval(File.read(model), model)
  end
end