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

DUPLICATE_DELIMITER =
'//'

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Constructor Details

- (CompletionMap) initialize(*globs)

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

- (Hash) alias_map (readonly)

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

- (Hash) map

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

+ (Array) ignore_paths

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

+ (Object) ignore_paths=(val)

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

- (String) [](completion)

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

- (Array) keys

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