Class: CLI::Mastermind::Plan
- Inherits:
-
Object
- Object
- CLI::Mastermind::Plan
- Includes:
- Interface, UserInterface
- Defined in:
- lib/cli/mastermind/plan.rb,
lib/cli/mastermind/plan/interface.rb
Defined Under Namespace
Modules: Interface
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Used in the interactive plan selector to display child plans.
Class Method Summary collapse
-
.load(filename) ⇒ Object
Loads a particular plan from the filesystem.
Instance Method Summary collapse
- #add_children(plans) ⇒ Object
- #call(options = nil) ⇒ Object
-
#get_child(name) ⇒ Object
(also: #[], #dig)
Get the child plan with the specified
name. - #has_children? ⇒ Boolean
-
#initialize(name, description = nil, filename = nil, &block) ⇒ Plan
constructor
A new instance of Plan.
Methods included from Interface
Methods included from UserInterface
#ask, #concurrently, #confirm, #enable_ui, #frame, #select, #spinner, #stylize, #titleize, #ui_enabled?
Constructor Details
#initialize(name, description = nil, filename = nil, &block) ⇒ Plan
Returns a new instance of Plan.
21 22 23 24 25 |
# File 'lib/cli/mastermind/plan.rb', line 21 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
11 12 13 |
# File 'lib/cli/mastermind/plan.rb', line 11 def children @children end |
Class Method Details
.load(filename) ⇒ Object
Loads a particular plan from the filesystem.
15 16 17 18 19 |
# File 'lib/cli/mastermind/plan.rb', line 15 def self.load(filename) ext = File.extname(filename) loader = Loader.find_loader(ext) loader.load(filename) end |
Instance Method Details
#add_children(plans) ⇒ Object
34 35 36 37 |
# File 'lib/cli/mastermind/plan.rb', line 34 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
43 44 45 46 47 48 |
# File 'lib/cli/mastermind/plan.rb', line 43 def call(=nil) case @block.arity when 1, -1 then instance_exec(, &@block) else instance_exec(&@block) end end |
#get_child(name) ⇒ Object Also known as: [], dig
Get the child plan with the specified name
28 29 30 |
# File 'lib/cli/mastermind/plan.rb', line 28 def get_child(name) @children[name] end |
#has_children? ⇒ Boolean
39 40 41 |
# File 'lib/cli/mastermind/plan.rb', line 39 def has_children? @children.any? end |