Class: CLI::Mastermind::Loader::PlanfileLoader::DSL
- Inherits:
-
Object
- Object
- CLI::Mastermind::Loader::PlanfileLoader::DSL
- Defined in:
- lib/cli/mastermind/loader/planfile_loader.rb
Instance Attribute Summary collapse
-
#plans ⇒ Object
readonly
Returns the value of attribute plans.
Instance Method Summary collapse
- #description(text) ⇒ Object (also: #desc)
-
#initialize(filename = nil, &block) ⇒ DSL
constructor
A new instance of DSL.
- #plan(name, plan_class = Plan, &block) ⇒ Object (also: #task)
- #plot(name, &block) ⇒ Object (also: #namespace)
Constructor Details
#initialize(filename = nil, &block) ⇒ DSL
Returns a new instance of DSL.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 18 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 ⇒ Object (readonly)
Returns the value of attribute plans.
16 17 18 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 16 def plans @plans end |
Instance Method Details
#description(text) ⇒ Object Also known as: desc
39 40 41 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 39 def description(text) @description = text end |
#plan(name, plan_class = Plan, &block) ⇒ Object Also known as: task
44 45 46 47 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 44 def plan(name, plan_class = Plan, &block) @plans << plan_class.new(name, @description, @filename, &block) @description = nil end |
#plot(name, &block) ⇒ Object Also known as: namespace
31 32 33 34 35 36 |
# File 'lib/cli/mastermind/loader/planfile_loader.rb', line 31 def plot(name, &block) plan = Plan.new name, @description, @filename @description = nil @plans << plan plan.add_children DSL.new(@filename, &block).plans end |