Class: Gitlab::FileFinder
- Inherits:
-
Object
- Object
- Gitlab::FileFinder
- Defined in:
- lib/gitlab/file_finder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
Instance Method Summary collapse
- #find(query, content_match_cutoff: nil) ⇒ Object
-
#initialize(project, ref) ⇒ FileFinder
constructor
A new instance of FileFinder.
Constructor Details
#initialize(project, ref) ⇒ FileFinder
Returns a new instance of FileFinder.
11 12 13 14 |
# File 'lib/gitlab/file_finder.rb', line 11 def initialize(project, ref) @project = project @ref = ref end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
7 8 9 |
# File 'lib/gitlab/file_finder.rb', line 7 def project @project end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
7 8 9 |
# File 'lib/gitlab/file_finder.rb', line 7 def ref @ref end |
Instance Method Details
#find(query, content_match_cutoff: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/file_finder.rb', line 16 def find(query, content_match_cutoff: nil) query = Gitlab::Search::Query.new(query, encode_binary: true) do filter :filename, matcher: ->(filter, blob) do ::Gitlab::UntrustedRegexp.new("(?i)#{filter[:regex_value]}$").match?(blob.binary_path) end filter :path, matcher: ->(filter, blob) do ::Gitlab::UntrustedRegexp.new("(?i)#{filter[:regex_value]}").match?(blob.binary_path) end filter :extension, matcher: ->(filter, blob) do ::Gitlab::UntrustedRegexp.new("(?i)\\.#{filter[:regex_value]}$").match?(blob.binary_path) end end content_match_cutoff = nil if query.filters.any? files = find_by_path(query.term) + find_by_content(query.term, { limit: content_match_cutoff }) files = query.filter_results(files) if query.filters.any? files rescue Gitlab::Git::Repository::NoRepository [] end |