Class: CLI::Mastermind::Loader::PlanfileLoader::DSL
- Inherits:
-
Object
- Object
- CLI::Mastermind::Loader::PlanfileLoader::DSL
- Extended by:
- Forwardable
- Defined in:
- lib/cli/mastermind/loader/planfile_loader.rb
Instance Attribute Summary collapse
-
#plans ⇒ Array<Plan>
readonly
The plans defined by the loaded file or block.
Instance Method Summary collapse
- #description(text) ⇒ Object (also: #desc)
-
#initialize(filename = nil, &block) ⇒ DSL
constructor
Loads and evaluates a local file or a given block.
-
#plan(name, plan_class = ExecutablePlan, &block) ⇒ void
(also: #task)
Defines an executable plan.
-
#plot(name, &block) ⇒ Object
(also: #namespace)
Describes a ParentPlan.
-
#set_alias(alias_to) ⇒ Object
Sets an alias on the previously created plan.
Constructor Details
#initialize(filename = nil, &block) ⇒ DSL
Loads and evaluates a local file or a given block.
If given both, the block takes priority.
31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#plans ⇒ Array<Plan> (readonly)
Returns the plans defined by the loaded file or block.
21 22 23 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 21 def plans @plans end |
Instance Method Details
#description(text) ⇒ Object Also known as: desc
57 58 59 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 57 def description(text) @description = text end |
#plan(name, plan_class = ExecutablePlan, &block) ⇒ void Also known as: task
This method returns an undefined value.
Defines an executable plan
68 69 70 71 |
# 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 |
#plot(name, &block) ⇒ Object Also known as: namespace
Describes a ParentPlan
48 49 50 51 52 53 |
# 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 |
#set_alias(alias_to) ⇒ Object
Sets an alias on the previously created plan
77 78 79 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 77 def set_alias(alias_to) @plans.last.add_alias(alias_to) end |