Class: Lightning::CompletionMap

Inherits:
Object
  • Object
show all
Defined in:
lib/lightning/completion_map.rb

Overview

Maps completions (file basenames) and aliases to their full paths given a Bolt object’s globs.

Constant Summary collapse

DUPLICATE_DELIMITER =
'//'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*globs) ⇒ CompletionMap

Returns a new instance of CompletionMap.



20
21
22
23
24
25
# File 'lib/lightning/completion_map.rb', line 20

def initialize(*globs)
  options = globs[-1].is_a?(Hash) ? globs.pop : {}
  globs.flatten!
  @map = create_globbed_map(globs)
  @alias_map = options[:aliases] || {}
end

Instance Attribute Details

#alias_mapHash (readonly)

Returns Maps aliases to full paths.

Returns:

  • (Hash)

    Maps aliases to full paths



18
19
20
# File 'lib/lightning/completion_map.rb', line 18

def alias_map
  @alias_map
end

#mapHash

Returns Maps file basenames to full paths.

Returns:

  • (Hash)

    Maps file basenames to full paths



16
17
18
# File 'lib/lightning/completion_map.rb', line 16

def map
  @map
end

Class Method Details

.ignore_pathsArray

Returns Regular expression paths to ignore. By default paths ending in . or .. are ignored.

Returns:

  • (Array)

    Regular expression paths to ignore. By default paths ending in . or .. are ignored.



6
7
8
# File 'lib/lightning/completion_map.rb', line 6

def self.ignore_paths
  @ignore_paths ||= (Lightning.config[:ignore_paths] || []) + %w{\.\.?$}
end

.ignore_paths=(val) ⇒ Object

Sets ignore_paths



11
12
13
# File 'lib/lightning/completion_map.rb', line 11

def self.ignore_paths=(val)
  @ignore_paths = val
end

Instance Method Details

#[](completion) ⇒ String

Returns Fetches full path of file or alias.

Returns:

  • (String)

    Fetches full path of file or alias



28
29
30
# File 'lib/lightning/completion_map.rb', line 28

def [](completion)
  @map[completion] || @alias_map[completion]
end

#keysArray

Returns List of unique basenames and aliases.

Returns:

  • (Array)

    List of unique basenames and aliases



33
34
35
# File 'lib/lightning/completion_map.rb', line 33

def keys
  (@map.keys + @alias_map.keys).uniq
end