Class: Yatte::ProjectSearch
- Inherits:
-
Object
- Object
- Yatte::ProjectSearch
- 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
Instance Method Summary collapse
- #git_repo? ⇒ Boolean
-
#initialize(root_dir = ".") ⇒ ProjectSearch
constructor
A new instance of ProjectSearch.
- #search(query) ⇒ Object
Constructor Details
#initialize(root_dir = ".") ⇒ ProjectSearch
Returns a new instance of ProjectSearch.
13 14 15 |
# File 'lib/yatte/project_search.rb', line 13 def initialize(root_dir = ".") @root_dir = File.(root_dir) end |
Instance Method Details
#git_repo? ⇒ Boolean
27 28 29 30 31 32 33 34 35 |
# File 'lib/yatte/project_search.rb', line 27 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
17 18 19 20 21 22 23 24 25 |
# File 'lib/yatte/project_search.rb', line 17 def search(query) return [] if query.length < MIN_QUERY_LENGTH if git_repo? git_grep(query) else ruby_search(query) end end |