Class: Backup::Config::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/backup/config/dsl.rb

Overview

Context for loading user config.rb and model files.

Defined Under Namespace

Classes: Error

Constant Summary collapse

Model =
Backup::Model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



76
77
78
# File 'lib/backup/config/dsl.rb', line 76

def initialize
  @_config_options = {}
end

Instance Attribute Details

#_config_optionsObject (readonly)

Returns the value of attribute _config_options.



74
75
76
# File 'lib/backup/config/dsl.rb', line 74

def _config_options
  @_config_options
end

Instance Method Details

#preconfigure(name, &block) ⇒ Object

Allows users to create preconfigured models.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/backup/config/dsl.rb', line 86

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