class Backup::Config::DSL

Context for loading user config.rb and model files.

Constants

Model

Attributes

_config_options[R]

Public Class Methods

new() click to toggle source
# File lib/backup/config/dsl.rb, line 75
def initialize
  @_config_options = {}
end

Private Class Methods

add_dsl_constants() click to toggle source

List the available database, storage, syncer, compressor, encryptor and notifier constants. These are used to define constant names within Backup::Config::DSL so that users may use a constant instead of a string. Nested namespaces are represented using Hashs. Deep nesting supported.

Example, instead of:

database "MySQL" do |mysql|
sync_with "RSync::Local" do |rsync|

You can do:

database MySQL do |mysql|
sync_with RSync::Local do |rsync|
# File lib/backup/config/dsl.rb, line 25
def add_dsl_constants
  create_modules(
    DSL,
    [ # Databases
      ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak', 'OpenLDAP', 'SQLite'],
      # Storages
      ['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP',
      'SFTP', 'SCP', 'RSync', 'Local'],
      # Compressors
      ['Gzip', 'Bzip2', 'Custom', 'Pbzip2', 'Lzma'],
      # Encryptors
      ['OpenSSL', 'GPG'],
      # Syncers
      [
        { 'Cloud' => ['CloudFiles', 'S3'] },
        { 'RSync' => ['Push', 'Pull', 'Local'] }
      ],
      # Notifiers
      ['Mail', 'Twitter', 'Campfire', 'Prowl',
      'Hipchat', 'PagerDuty', 'Pushover', 'HttpPost', 'Nagios',
      'Slack', 'FlowDock', 'Zabbix', 'Ses', 'DataDog', 'Command']
    ]
  )
end
create_modules(scope, names) click to toggle source
# File lib/backup/config/dsl.rb, line 50
def create_modules(scope, names)
  names.flatten.each do |name|
    if name.is_a?(Hash)
      name.each do |key, val|
        create_modules(get_or_create_empty_module(scope, key), [val])
      end
    else
      get_or_create_empty_module(scope, name)
    end
  end
end
get_or_create_empty_module(scope, const) click to toggle source
# File lib/backup/config/dsl.rb, line 62
def get_or_create_empty_module(scope, const)
  if scope.const_defined?(const)
    scope.const_get(const)
  else
    scope.const_set(const, Module.new)
  end
end

Public Instance Methods

preconfigure(name, &block) click to toggle source

Allows users to create preconfigured models.

# File lib/backup/config/dsl.rb, line 85
def preconfigure(name, &block)
  unless name.is_a?(String) && name =~ /^[A-Z]/
    raise Error, "Preconfigured model names must be given as a string " +
                  "and start with a capital letter."
  end

  if DSL.const_defined?(name)
    raise Error, "'#{ name }' is already in use " +
                  "and can not be used for a preconfigured model."
  end

  DSL.const_set(name, Class.new(Model))
  DSL.const_get(name).preconfigure(&block)
end