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
-
#add_alias(alias_to) ⇒ Object
Defines a plan alias which allows this plan to be accessed using another string than its name.
-
#call(options = nil) ⇒ Object
(also: #execute)
abstract
Entrypoint called by Mastermind.
-
#has_children? ⇒ false
If this plan has children.
- #initialize(name, description = nil, filename = nil, &block) ⇒ Object
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
Defines a plan alias which allows this plan to be accessed using another string than its name.
72 73 74 |
# File 'lib/cli/mastermind/plan.rb', line 72 def add_alias(alias_to) @aliases.add alias_to.to_s end |
#call(options = nil) ⇒ Object Also known as: execute
Entrypoint called by Mastermind
63 64 65 |
# File 'lib/cli/mastermind/plan.rb', line 63 def call(=nil) raise NotImplementedError end |
#has_children? ⇒ false
If this plan has children.
Implemented for compatibility with ParentPlan to make plan traversal easier.
54 55 56 |
# File 'lib/cli/mastermind/plan.rb', line 54 def has_children? false end |
#initialize(name, description = nil, filename = nil, &block) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/cli/mastermind/plan.rb', line 40 def initialize(name, description=nil, filename=nil, &block) @name = name.to_s.freeze @description = description.freeze @filename = filename # TODO: Move this to ExecutablePlan? @block = block @aliases = Set.new end |