Class: TabTab::Definition::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/tabtab/definitions/default.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#contents, #definition_block, #parent

Instance Method Summary collapse

Methods inherited from Base

#[], #autocompletable?, #command, #completions_of_contents, #current_token, #definition_type?, #filtered_completions, #find_active_definition_for_last_token, #flags, #tokens_consumed, #yield_definition_block

Constructor Details

#initialize(parent, description = nil, &definition_block) ⇒ Default

Returns a new instance of Default.



4
5
6
7
# File 'lib/tabtab/definitions/default.rb', line 4

def initialize(parent, description=nil, &definition_block)
  @description = description
  super parent, &definition_block
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/tabtab/definitions/default.rb', line 3

def description
  @description
end

Instance Method Details

#definition_typeObject



9
10
11
# File 'lib/tabtab/definitions/default.rb', line 9

def definition_type
  :default
end

#matches_token?(cmd_line_token) ⇒ Boolean

Determines if current token matches this command’s name

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tabtab/definitions/default.rb', line 28

def matches_token?(cmd_line_token)
  results = yield_result_block
  case results
  when String
    results == cmd_line_token.to_s
  when Array
    results.include?(cmd_line_token.to_s)
  else
    false
  end
end

#own_completionsObject



13
14
15
# File 'lib/tabtab/definitions/default.rb', line 13

def own_completions
  yield_result_block
end

#yield_result_blockObject



17
18
19
20
21
22
23
24
25
# File 'lib/tabtab/definitions/default.rb', line 17

def yield_result_block
  if definition_block.arity == -1 || definition_block.arity == 0
    definition_block.call
  elsif definition_block.arity == 1
    definition_block.call(self)
  else
    raise TabTab::Definition::InvalidDefinitionBlockArguments
  end
end