Class: CLI::Mastermind::Plan

Inherits:
Object
  • Object
show all
Includes:
Interface
Defined in:
lib/cli/mastermind/plan.rb,
lib/cli/mastermind/plan/interface.rb

Defined Under Namespace

Modules: Interface

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interface

#add_alias, included

Constructor Details

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

Returns a new instance of Plan.



20
21
22
23
24
# File 'lib/cli/mastermind/plan.rb', line 20

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



10
11
12
# File 'lib/cli/mastermind/plan.rb', line 10

def children
  @children
end

Class Method Details

.load(filename) ⇒ Object

Loads a particular plan from the filesystem.

See Also:



14
15
16
17
18
# File 'lib/cli/mastermind/plan.rb', line 14

def self.load(filename)
  ext = File.extname(filename)
  loader = Loader.find_loader(ext)
  loader.load(filename)
end

Instance Method Details

#add_children(plans) ⇒ Object

Raises:



33
34
35
36
# File 'lib/cli/mastermind/plan.rb', line 33

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

#call(options = nil) ⇒ Object



42
43
44
45
46
47
# File 'lib/cli/mastermind/plan.rb', line 42

def call(options=nil)
  case @block.arity
  when 1, -1 then instance_exec(options, &@block)
  else            instance_exec(&@block)
  end
end

#get_child(name) ⇒ Object Also known as: [], dig

Get the child plan with the specified name



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

def get_child(name)
  @children[name]
end

#has_children?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/cli/mastermind/plan.rb', line 38

def has_children?
  @children.any?
end