Class: TabTab::Completions::File

Inherits:
Object
  • Object
show all
Defined in:
lib/tabtab/completions/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, app_name, current_token, previous_token, global_config = {}) ⇒ File

Returns a new instance of File.



4
5
6
7
8
9
10
# File 'lib/tabtab/completions/file.rb', line 4

def initialize(file_path, app_name, current_token, previous_token, global_config = {})
  @file_path      = file_path
  @app_name       = app_name
  @current_token  = current_token
  @previous_token = previous_token
  @global_config  = global_config
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



2
3
4
# File 'lib/tabtab/completions/file.rb', line 2

def app_name
  @app_name
end

#current_tokenObject (readonly)

Returns the value of attribute current_token.



2
3
4
# File 'lib/tabtab/completions/file.rb', line 2

def current_token
  @current_token
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



2
3
4
# File 'lib/tabtab/completions/file.rb', line 2

def file_path
  @file_path
end

#global_configObject (readonly)

Returns the value of attribute global_config.



2
3
4
# File 'lib/tabtab/completions/file.rb', line 2

def global_config
  @global_config
end

#previous_tokenObject (readonly)

Returns the value of attribute previous_token.



2
3
4
# File 'lib/tabtab/completions/file.rb', line 2

def previous_token
  @previous_token
end

Instance Method Details

#extractObject

Returns the sub-list of all options filtered by a common prefix e.g. if current extract list is [‘–help’, ‘–extra’, ‘-h’, ‘-x’] then starts_with(‘–’) returns [‘–help’, ‘–extra’]



15
16
17
18
19
20
21
22
# File 'lib/tabtab/completions/file.rb', line 15

def extract
  if File.exists?(file_path)
    load file_path
    TabTab::Definition[app_name].extract_completions(previous_token, current_token, global_config)
  else
    []
  end
end