Class: CLI::Mastermind::Plan
- Inherits:
-
Object
- Object
- CLI::Mastermind::Plan
- Extended by:
- Forwardable
- Includes:
- Interface
- Defined in:
- lib/cli/mastermind/plan.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Used in the interactive plan selector to display child plans.
-
#description ⇒ Object
readonly
Displayed in the non-interactive list of available plans.
-
#name ⇒ Object
readonly
The name of the plan.
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, &block) ⇒ Plan
constructor
A new instance of Plan.
Methods included from Interface
#ask, #confirm, #enable_ui, #frame, #select, #spinner, #titleize, #ui_enabled?
Constructor Details
#initialize(name, description = nil, &block) ⇒ Plan
27 28 29 30 31 32 |
# File 'lib/cli/mastermind/plan.rb', line 27 def initialize(name, description=nil, &block) @name = name.to_s.freeze @description = description.freeze @block = block @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Used in the interactive plan selector to display child plans
17 18 19 |
# File 'lib/cli/mastermind/plan.rb', line 17 def children @children end |
#description ⇒ Object (readonly)
Displayed in the non-interactive list of available plans
14 15 16 |
# File 'lib/cli/mastermind/plan.rb', line 14 def description @description end |
#name ⇒ Object (readonly)
The name of the plan. Used to specify the plan from the command line or from the interactive menu
11 12 13 |
# File 'lib/cli/mastermind/plan.rb', line 11 def name @name end |
Class Method Details
.load(filename) ⇒ Object
Loads a particular plan from the filesystem.
21 22 23 24 25 |
# File 'lib/cli/mastermind/plan.rb', line 21 def self.load(filename) ext = File.extname(filename) loader = Loader.find_loader(ext) loader.load(filename) end |
Instance Method Details
#add_children(plans) ⇒ Object
41 42 43 44 |
# File 'lib/cli/mastermind/plan.rb', line 41 def add_children(plans) raise 'Cannot add child plans to a plan with an action', InvalidPlanError unless @block.nil? plans.each { |plan| @children[plan.name] = plan } end |
#call(options = nil) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/cli/mastermind/plan.rb', line 50 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
35 36 37 |
# File 'lib/cli/mastermind/plan.rb', line 35 def get_child(name) @children[name] end |
#has_children? ⇒ Boolean
46 47 48 |
# File 'lib/cli/mastermind/plan.rb', line 46 def has_children? @children.any? end |