class CLI::Mastermind::Configuration::DSL
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.
Public Class Methods
@param config [Configuration] the configuration object used by the DSL
@param filename [String] the path to the masterplan to be loaded
# 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
Public Instance Methods
Syntactic sugar on top of `project_root` to specify that the current masterplan resides in the root of the project.
@see project_root
# File lib/cli/mastermind/configuration.rb, line 202 def at_project_root project_root File.dirname(@filename) end
Add arbitrary configuration attributes to the configuration object. Use this to add plan specific configuration options.
@overload configure(attribute, value=nil, &block)
@example configure(:foo, 'bar') @example configure(:foo) { 'bar' } @param attribute [String,Symbol] the attribute to define @param value [] the value to assign @param block [#call,nil] a callable that will return the value
@overload configure(attribute)
@example configure(foo: 'bar') @example configure('foo' => -> { 'bar' } # not recommended, but should work @param attribute [Hash] a single entry hash with the key as the attribute name and value as the corresponding value
# 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 a user alias. User aliases are expanded as part of plan selection. @see ArgParse#do_command_expansion!
@param name [String] the string to be replaced @param arguments [String,Array<String>] the replacement
# File lib/cli/mastermind/configuration.rb, line 267 def define_alias(name, arguments) @config.define_alias(name, arguments) end
Syntactic sugar on top of `plan_files` to specify that plans exist in a plans/
directory in the current directory.
@see plan_files
# File lib/cli/mastermind/configuration.rb, line 226 def has_plan_files plan_files File.join(File.dirname(@filename), 'plans') end
Specifies that a specific plan file exists at the given filename
.
@param files [Array<String>] an array of planfile paths
# 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
Specify that plans exist in the given directory
. Must be a valid directory.
@param directory [String] path to a directory containing planfiles @raise [InvalidDirectoryError] if directory
is not a directory
# 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
Specifies the root of the project. root
must be a directory.
@param root [String] the root directory of the project @raise [InvalidDirectoryError] if root
is not a directory
# 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
Specifies that another masterplan should also be loaded when loading this masterplan. NOTE: This immediately loads the other masterplan.
@param filename [String] the path to the masterplan to be loaded
# File lib/cli/mastermind/configuration.rb, line 181 def see_also(filename) @config.load_masterplan(File.expand_path(filename)) end
SKip confirmation before plan execution. Identical to -A.
# File lib/cli/mastermind/configuration.rb, line 273 def skip_confirmation @config.skip_confirmation! end
Private Instance Methods
Used during planfile loading with a Dir.glob to load only supported planfiles
@return [String] a comma separated list of supported file extensions
# File lib/cli/mastermind/configuration.rb, line 282 def supported_extensions Loader.supported_extensions.join(',') end