Class: Codeowners::Cli::SuggestFileFromPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/codeowners/cli/suggest_file_from_pattern.rb

Overview

Case the user have ‘fzf` installed, it works building suggestions from `fzf`. See more on #fzf_query.

Without ‘fzf` it tries to suggest patterns using fuzzy match search picking all the files from the parent folder of the current pattern.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ SuggestFileFromPattern

Returns a new instance of SuggestFileFromPattern.



11
12
13
# File 'lib/codeowners/cli/suggest_file_from_pattern.rb', line 11

def initialize(pattern)
  @pattern = pattern
end

Class Method Details

.installed_fzf?Boolean

Checks if fzf is installed.

Returns:

  • (Boolean)


28
29
30
# File 'lib/codeowners/cli/suggest_file_from_pattern.rb', line 28

def self.installed_fzf?
  system('fzf --version > /dev/null 2>&1')
end

Instance Method Details

#pick_suggestionObject

Pick suggestion from current pattern If have fzf installed, pick suggestions using fzf otherwise fallback to the default fuzzy match searching for the file from the parent folder.



19
20
21
# File 'lib/codeowners/cli/suggest_file_from_pattern.rb', line 19

def pick_suggestion
  strategy_class.new(@pattern).pick_suggestions
end

#strategy_classObject



23
24
25
# File 'lib/codeowners/cli/suggest_file_from_pattern.rb', line 23

def strategy_class
  SuggestFileFromPattern.installed_fzf? ? FilesFromFZFSearch : FilesFromParentFolder
end