Class: CLI::Mastermind::Configuration::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/mastermind/configuration.rb

Overview

Describes the DSL used in masterplan files.

See the .masterplan file in the root of this repo for a full example of the available options.

Instance Method Summary collapse

Constructor Details

#initialize(config, filename) ⇒ DSL

Returns a new instance of DSL.

Parameters:

  • config (Configuration)

    the configuration object used by the DSL

  • filename (String)

    the path to the masterplan to be loaded



171
172
173
174
175
# File 'lib/cli/mastermind/configuration.rb', line 171

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 masterplan resides in the root of the project.

See Also:



202
203
204
# File 'lib/cli/mastermind/configuration.rb', line 202

def at_project_root
  project_root File.dirname(@filename)
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



254
255
256
257
258
259
# File 'lib/cli/mastermind/configuration.rb', line 254

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

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

#define_alias(name, arguments) ⇒ Object

Define a user alias. User aliases are expanded as part of plan selection.

Parameters:

  • name (String)

    the string to be replaced

  • arguments (String, Array<String>)

    the replacement

See Also:



267
268
269
# File 'lib/cli/mastermind/configuration.rb', line 267

def define_alias(name, arguments)
  @config.define_alias(name, arguments)
end

#has_plan_filesObject

Syntactic sugar on top of ‘plan_files` to specify that plans exist in a plans/ directory in the current directory.

See Also:



226
227
228
# File 'lib/cli/mastermind/configuration.rb', line 226

def has_plan_files
  plan_files File.join(File.dirname(@filename), 'plans')
end

#plan_file(*files) ⇒ Object

Specifies that a specific plan file exists at the given filename.

Parameters:

  • files (Array<String>)

    an array of planfile paths



233
234
235
236
237
# File 'lib/cli/mastermind/configuration.rb', line 233

def plan_file(*files)
  files = files.map { |file| File.expand_path file }

  @config.add_plans(files)
end

#plan_files(directory) ⇒ Object

Specify that plans exist in the given directory. Must be a valid directory.

Parameters:

  • directory (String)

    path to a directory containing planfiles

Raises:



211
212
213
214
215
216
217
218
219
220
# File 'lib/cli/mastermind/configuration.rb', line 211

def plan_files(directory)
  unless Dir.exist? directory
    raise InvalidDirectoryError.new('Invalid plan file directory', directory)
  end

  planfiles = Dir.glob(File.join(directory, '**', "*{#{supported_extensions}}"))
  planfiles.map! { |file| File.expand_path(file) }

  @config.add_plans(planfiles)
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:



190
191
192
193
194
195
196
# File 'lib/cli/mastermind/configuration.rb', line 190

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 masterplan should also be loaded when loading this masterplan. NOTE: This immediately loads the other masterplan.

Parameters:

  • filename (String)

    the path to the masterplan to be loaded



181
182
183
# File 'lib/cli/mastermind/configuration.rb', line 181

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

#skip_confirmationObject

SKip confirmation before plan execution. Identical to -A.



273
274
275
# File 'lib/cli/mastermind/configuration.rb', line 273

def skip_confirmation
  @config.skip_confirmation!
end