Class: CLI::Mastermind::ParentPlan
- Inherits:
-
Object
- Object
- CLI::Mastermind::ParentPlan
- Extended by:
- Forwardable
- Includes:
- Plan, Enumerable
- Defined in:
- lib/cli/mastermind/parent_plan.rb
Overview
Plan implementation designed to hold other plans forming the intermediate nodes on the tree of loaded plans.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Used in the interactive plan selector to display child plans.
Instance Method Summary collapse
-
#add_children(plans) ⇒ Void
Adds new children to this plan.
-
#get_child(name) ⇒ Plan?
(also: #[], #dig)
Get the child plan with the specified
name
. -
#has_children? ⇒ Boolean
If this plan has any children.
-
#initialize(name, description = nil, filename = nil, &block) ⇒ ParentPlan
constructor
A new instance of ParentPlan.
Methods included from Plan
Constructor Details
#initialize(name, description = nil, filename = nil, &block) ⇒ ParentPlan
Returns a new instance of ParentPlan.
16 17 18 19 20 |
# File 'lib/cli/mastermind/parent_plan.rb', line 16 def initialize(name, description=nil, filename=nil, &block) super @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Used in the interactive plan selector to display child plans
12 13 14 |
# File 'lib/cli/mastermind/parent_plan.rb', line 12 def children @children end |
Instance Method Details
#add_children(plans) ⇒ Void
Adds new children to this plan
43 44 45 46 |
# File 'lib/cli/mastermind/parent_plan.rb', line 43 def add_children(plans) raise InvalidPlanError, 'Cannot add child plans to a plan with an action' unless @block.nil? plans.each(&method(:incorporate_plan)) end |
#get_child(name) ⇒ Plan? Also known as: [], dig
Get the child plan with the specified name
.
This method also checks plan aliases, so the given name
can also be a plan’s alias.
29 30 31 32 |
# File 'lib/cli/mastermind/parent_plan.rb', line 29 def get_child(name) return @children[name] if @children.has_key? name @children.each_value.find { |child| child.aliases.include? name } end |
#has_children? ⇒ Boolean
Returns if this plan has any children.
49 50 51 |
# File 'lib/cli/mastermind/parent_plan.rb', line 49 def has_children? @children.any? end |