Class: Yatte::ProjectSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/yatte/project_search.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

MAX_RESULTS =
100
MAX_PER_FILE =
5
MIN_QUERY_LENGTH =
2
SKIP_DIRS =
%w[.git node_modules vendor/bundle tmp log].freeze
SKIP_EXTENSIONS =
%w[
  .png .jpg .jpeg .gif .ico .webp
  .woff .woff2 .ttf .eot
  .pdf .zip .gz .tar .db .sqlite3
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root_dir = ".") ⇒ ProjectSearch

Returns a new instance of ProjectSearch.



20
21
22
23
# File 'lib/yatte/project_search.rb', line 20

def initialize(root_dir = ".")
  @root_dir = File.expand_path(root_dir)
  @search_mode = nil
end

Instance Method Details

#git_repo?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'lib/yatte/project_search.rb', line 35

def git_repo?
  _, _, status = Open3.capture3(
    "git", "rev-parse", "--is-inside-work-tree",
    chdir: @root_dir
  )
  status.success?
rescue Errno::ENOENT
  false
end

#search(query) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/yatte/project_search.rb', line 25

def search(query)
  return [] if query.length < MIN_QUERY_LENGTH

  case search_mode
  when :git_grep then git_grep(query)
  when :grep then external_grep(query)
  else ruby_search(query)
  end
end