class CLI::Mastermind::Loader::PlanfileLoader::DSL

Attributes

plans[R]

@return [Array<Plan>] the plans defined by the loaded file or block

Public Class Methods

new(filename=nil, &block) click to toggle source

Loads and evaluates a local file or a given block.

If given both, the block takes priority.

@example DSL.new('path/to/file.plan') @example DSL.new { …methods go here… } @param filename [String,nil] the name of the file that contains this plan @param block [#call,nil] a block to evaluate

# File lib/cli/mastermind/loader/planfile_loader.rb, line 31
def initialize(filename=nil, &block)
  @plans = []
  @filename = filename

  if block_given?
    instance_eval(&block)
  elsif File.exists? filename
    instance_eval(File.read(filename), filename, 0)
  else
    raise InvalidPlanfileError, 'Must provide valid path to a planfile or a block'
  end
end

Public Instance Methods

desc(text)
Alias for: description
description(text) click to toggle source

@param text [String] the description of the next plan

# File lib/cli/mastermind/loader/planfile_loader.rb, line 57
def description(text)
  @description = text
end
Also aliased as: desc
namespace(name, &block)
Alias for: plot
plan(name, plan_class = ExecutablePlan, &block) click to toggle source

Defines an executable plan

@param name [String] the name of the plan @param plan_class [Plan] the plan class @param block [#call] passed into the newly created plan @return [void]

# File lib/cli/mastermind/loader/planfile_loader.rb, line 68
def plan(name, plan_class = ExecutablePlan, &block)
  @plans << plan_class.new(name, @description, @filename, &block)
  @description = nil
end
Also aliased as: task
plot(name, &block) click to toggle source

Describes a ParentPlan

@param name [String] the name of the plan @param block [#call] passed to a new DSL object to define more plans

# File lib/cli/mastermind/loader/planfile_loader.rb, line 48
def plot(name, &block)
  plan = ParentPlan.new name, @description, @filename
  @description = nil
  @plans << plan
  plan.add_children DSL.new(@filename, &block).plans
end
Also aliased as: namespace
set_alias(alias_to) click to toggle source

Sets an alias on the previously created plan

@param alias_to [String] the alias to add

# File lib/cli/mastermind/loader/planfile_loader.rb, line 77
def set_alias(alias_to)
  @plans.last.add_alias(alias_to)
end
task(name, plan_class = ExecutablePlan, &block)
Alias for: plan