Class: Executable::Completion
- Inherits:
-
Object
- Object
- Executable::Completion
- Defined in:
- lib/executable/completion.rb
Overview
Encpsulates command completion.
Instance Attribute Summary collapse
-
#cli_class ⇒ Object
readonly
The Executable subclass to which this help applies.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(cli_class) ⇒ Completion
constructor
Setup new completion object.
- #inspect ⇒ Object
- #options ⇒ Object
-
#subcommands ⇒ String, NilClass
List of subcommands converted to a printable string.
- #to_s ⇒ Object
Constructor Details
#initialize(cli_class) ⇒ Completion
Setup new completion object.
10 11 12 13 14 15 |
# File 'lib/executable/completion.rb', line 10 def initialize(cli_class) @cli_class = cli_class @subcommands = nil @options = nil end |
Instance Attribute Details
#cli_class ⇒ Object (readonly)
The Executable subclass to which this help applies.
23 24 25 |
# File 'lib/executable/completion.rb', line 23 def cli_class @cli_class end |
Instance Method Details
#call(*args) ⇒ Object
55 56 57 |
# File 'lib/executable/completion.rb', line 55 def call(*args) puts self end |
#inspect ⇒ Object
18 |
# File 'lib/executable/completion.rb', line 18 alias_method :inspect, :to_s |
#options ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/executable/completion.rb', line 36 def @options ||= ( method_list.map do |meth| case meth.name when /^(.*?)[\!\=]$/ name = meth.name.to_s.chomp('!').chomp('=') mark = name.to_s.size == 1 ? '-' : '--' mark + name end end.compact.sort ) end |
#subcommands ⇒ String, NilClass
List of subcommands converted to a printable string.
But will return nil if there are no subcommands.
31 32 33 |
# File 'lib/executable/completion.rb', line 31 def subcommands @subcommands ||= @cli_class.subcommands.keys end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/executable/completion.rb', line 50 def to_s (subcommands + ).join(' ') end |