Class: Samovar::Completion::Context
- Inherits:
-
Object
- Object
- Samovar::Completion::Context
- Defined in:
- lib/samovar/completion/context.rb
Overview
The context provided to dynamic completion callbacks.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
- #The token being completed.(tokenbeingcompleted.) ⇒ Object readonly
- #The truncated command-line arguments.(truncatedcommand-linearguments.) ⇒ Object readonly
Class Method Summary collapse
-
.for(command_class, arguments, environment: ENV) ⇒ Object
Build a context for a command class and argument list.
Instance Method Summary collapse
-
#complete ⇒ Object
Complete the current command class.
-
#complete_command(command_class, words = []) ⇒ Object
Complete the given command class with completed words.
-
#complete_rows(table, input) ⇒ Object
Complete the rows in a command table.
-
#initialize(table, arguments, current, row = nil, environment: ENV) ⇒ Context
constructor
Initialize a new completion context.
- #The command table to complete.=(commandtabletocomplete. = (value)) ⇒ Object
- #The environment for completion callbacks.=(environment) ⇒ Object
- #The parser row whose value is being completed.=(parserrowwhosevalueisbeingcompleted. = (value)) ⇒ Object
-
#with_row(row) ⇒ Object
Create a context for completing the given parser row.
-
#words ⇒ Object
The completed words before the current token.
Constructor Details
#initialize(table, arguments, current, row = nil, environment: ENV) ⇒ Context
Initialize a new completion context.
34 35 36 37 38 39 40 |
# File 'lib/samovar/completion/context.rb', line 34 def initialize(table, arguments, current, row = nil, environment: ENV) @table = table @arguments = arguments @current = current @row = row @environment = environment end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
46 47 48 |
# File 'lib/samovar/completion/context.rb', line 46 def arguments @arguments end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
49 50 51 |
# File 'lib/samovar/completion/context.rb', line 49 def current @current end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
55 56 57 |
# File 'lib/samovar/completion/context.rb', line 55 def environment @environment end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
52 53 54 |
# File 'lib/samovar/completion/context.rb', line 52 def row @row end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
43 44 45 |
# File 'lib/samovar/completion/context.rb', line 43 def table @table end |
#The token being completed.(tokenbeingcompleted.) ⇒ Object (readonly)
49 |
# File 'lib/samovar/completion/context.rb', line 49 attr :current |
#The truncated command-line arguments.(truncatedcommand-linearguments.) ⇒ Object (readonly)
46 |
# File 'lib/samovar/completion/context.rb', line 46 attr :arguments |
Class Method Details
.for(command_class, arguments, environment: ENV) ⇒ Object
Build a context for a command class and argument list.
18 19 20 21 22 23 24 25 |
# File 'lib/samovar/completion/context.rb', line 18 def self.for(command_class, arguments, environment: ENV) return self.new( command_class.table.merged, arguments, arguments.last || "", environment: environment, ) end |
Instance Method Details
#complete ⇒ Object
Complete the current command class.
81 82 83 |
# File 'lib/samovar/completion/context.rb', line 81 def complete complete_rows(@table, words) end |
#complete_command(command_class, words = []) ⇒ Object
Complete the given command class with completed words.
90 91 92 |
# File 'lib/samovar/completion/context.rb', line 90 def complete_command(command_class, words = []) complete_rows(command_class.table.merged, words) end |
#complete_rows(table, input) ⇒ Object
Complete the rows in a command table. The input array is mutable and may be consumed by parser rows.
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/samovar/completion/context.rb', line 100 def complete_rows(table, input) collected = [] table.each do |row| if row.respond_to?(:complete) if result = row.complete(input, self, collected) return result end end end return Result.new(collected) end |
#The command table to complete.=(commandtabletocomplete. = (value)) ⇒ Object
43 |
# File 'lib/samovar/completion/context.rb', line 43 attr :table |
#The environment for completion callbacks.=(environment) ⇒ Object
55 |
# File 'lib/samovar/completion/context.rb', line 55 attr :environment |
#The parser row whose value is being completed.=(parserrowwhosevalueisbeingcompleted. = (value)) ⇒ Object
52 |
# File 'lib/samovar/completion/context.rb', line 52 attr :row |
#with_row(row) ⇒ Object
Create a context for completing the given parser row.
61 62 63 64 65 66 67 68 69 |
# File 'lib/samovar/completion/context.rb', line 61 def with_row(row) return self.class.new( @table, @arguments, @current, row, environment: @environment, ) end |
#words ⇒ Object
The completed words before the current token.
74 75 76 |
# File 'lib/samovar/completion/context.rb', line 74 def words @arguments.take(@arguments.size - 1) end |