Class: ConfStack::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/conf_stack.rb

Overview

Describes the DSL used in configuration files.

Instance Method Summary collapse

Constructor Details

#initialize(config, filename) ⇒ DSL

Returns a new instance of DSL.

Parameters:

  • config (ConfStack)

    the configuration object used by the DSL

  • filename (String)

    the path to the configuration file to be loaded



136
137
138
139
140
# File 'lib/conf_stack.rb', line 136

def initialize(config, filename)
  @config = config
  @filename = filename
  instance_eval(File.read(filename), filename, 0) if File.exists? filename
end

Instance Method Details

#at_project_rootObject

Syntactic sugar on top of project_root to specify that the current file resides in the root of the project.

See Also:



167
168
169
# File 'lib/conf_stack.rb', line 167

def at_project_root
  project_root File.dirname(@filename)
end

#backward_compatability(*args, **kwargs) ⇒ Object Also known as: plan_files, has_plan_files, plan_file, define_alias, skip_confirmation

The following methods are maintained for backwards compatability with .masterplan files used by Mastermind



196
197
# File 'lib/conf_stack.rb', line 196

def backward_compatability(*args, **kwargs)
end

#configure(attribute, value = nil, &block) ⇒ Object #configure(attribute) ⇒ Object Also known as: set

Add arbitrary configuration attributes to the configuration object. Use this to add plan specific configuration options.

Overloads:

  • #configure(attribute, value = nil, &block) ⇒ Object

    Examples:

    configure(:foo, ‘bar’)

    configure(:foo) { ‘bar’ }

    Parameters:

    • attribute (String, Symbol)

      the attribute to define

    • value (defaults to: nil)

      the value to assign

    • block (#call, nil)

      a callable that will return the value

  • #configure(attribute) ⇒ Object

    Examples:

    configure(foo: ‘bar’)

    configure(‘foo’ => -> { ‘bar’ } # not recommended, but should work

    Parameters:

    • attribute (Hash)

      a single entry hash with the key as the attribute name and value as the corresponding value



186
187
188
189
190
191
# File 'lib/conf_stack.rb', line 186

def configure(attribute, value=nil, &block)
  attribute, value = attribute.first if attribute.is_a? Hash

  ConfStack.add_attribute(attribute)
  @config.public_send "#{attribute}=", value, &block
end

#project_root(root) ⇒ Object

Specifies the root of the project. root must be a directory.

Parameters:

  • root (String)

    the root directory of the project

Raises:



155
156
157
158
159
160
161
# File 'lib/conf_stack.rb', line 155

def project_root(root)
  unless Dir.exist? root
    raise InvalidDirectoryError.new('Invalid project root', root)
  end

  @config.project_root = root
end

#see_also(filename) ⇒ Object

Specifies that another file should also be loaded when loading this file. NOTE: This immediately loads the other file.

Parameters:

  • filename (String)

    the path to the file to be loaded



146
147
148
# File 'lib/conf_stack.rb', line 146

def see_also(filename)
  @config.load_configuration_file(File.expand_path(filename))
end