Module: CLI::Mastermind::Plan

Extended by:
Forwardable
Included in:
ExecutablePlan, ParentPlan
Defined in:
lib/cli/mastermind/plan.rb

Overview

The plan interface is everything that is required in order for an object to be usable as a plan.

Objects adhering to this interface must implement their own call method. This method is what is invoked by Mastermind to execute a plan.

Mastermind assumes that any plan it encounters could have children, hence the has_children? method here. Since the default PlanfileLoader doesn’t permit custom plan classes when defining a plan with children, it’s assumed that any custom plans (which include this interface) won’t have any children at all.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cli/mastermind/plan.rb', line 17

def self.included(base)
  base.class_eval do
    # The name of the plan.  Used to specify the plan from the command line
    # or from the interactive menu
    attr_reader :name

    # Displayed in the non-interactive list of available plans
    attr_reader :description

    # The file this plan was loaded from, if any
    attr_reader :filename

    # Provides shorter names for the plan
    attr_reader :aliases

    include UserInterface
  end
end

Instance Method Details

#add_alias(alias_to) ⇒ Object



53
54
55
# File 'lib/cli/mastermind/plan.rb', line 53

def add_alias(alias_to)
  @aliases.add alias_to.to_s
end

#call(options = nil) ⇒ Object Also known as: execute

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/cli/mastermind/plan.rb', line 48

def call(options=nil)
  raise NotImplementedError
end

#has_children?Boolean

Returns:

  • (Boolean)


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

def has_children?
  false
end

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



36
37
38
39
40
41
42
# File 'lib/cli/mastermind/plan.rb', line 36

def initialize(name, description=nil, filename=nil, &block)
  @name = name.to_s.freeze
  @description = description.freeze
  @filename = filename
  @block = block
  @aliases = Set.new
end