Class: CLI::Mastermind::ParentPlan

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Plan, Enumerable
Defined in:
lib/cli/mastermind/parent_plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Plan

#add_alias, #call, included

Constructor Details

#initialize(name, description = nil, filename = nil, &block) ⇒ ParentPlan

Returns a new instance of ParentPlan.



11
12
13
14
15
# File 'lib/cli/mastermind/parent_plan.rb', line 11

def initialize(name, description=nil, filename=nil, &block)
  super

  @children = {}
end

Instance Attribute Details

#childrenObject (readonly)

Used in the interactive plan selector to display child plans



9
10
11
# File 'lib/cli/mastermind/parent_plan.rb', line 9

def children
  @children
end

Instance Method Details

#add_children(plans) ⇒ Object

Raises:



27
28
29
30
# File 'lib/cli/mastermind/parent_plan.rb', line 27

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) ⇒ Object Also known as: [], dig

Get the child plan with the specified name



18
19
20
21
# File 'lib/cli/mastermind/parent_plan.rb', line 18

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:

  • (Boolean)


32
33
34
# File 'lib/cli/mastermind/parent_plan.rb', line 32

def has_children?
  @children.any?
end