Class: Fcom::Querier
- Inherits:
-
Object
- Object
- Fcom::Querier
- Includes:
- OptionsHelpers, MemoWise
- Defined in:
- lib/fcom/querier.rb
Overview
This class executes a system command to retrieve the git history, which is passed through ‘rg` (ripgrep), and then ultimately is fed back to `fcom` for parsing.
Instance Method Summary collapse
-
#initialize(options) ⇒ Querier
constructor
A new instance of Querier.
-
#query ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(options) ⇒ Querier
Returns a new instance of Querier.
11 12 13 |
# File 'lib/fcom/querier.rb', line 11 def initialize() @options = end |
Instance Method Details
#query ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/MethodLength
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fcom/querier.rb', line 18 def query expression_to_match = search_string expression_to_match = Regexp.escape(expression_to_match).gsub('\\ ', ' ') unless regex_mode? if expression_to_match.nil? || expression_to_match.empty? puts('provide expression to match as first argument') exit end quote = expression_to_match.include?('"') ? "'" : '"' commands = filename_by_most_recent_containing_commit.map do |commit, path_at_commit| <<~COMMAND.squish git log --format="commit %s|%H|%an|%cr (%ci)" --patch --full-diff --topo-order --no-textconv #{%(--author="#{}") if } #{days_limiter} #{commit} -- #{path_at_commit} | rg #{quote}(#{expression_to_match})|(^commit )|(^diff )#{quote} --color never #{'--ignore-case' if ignore_case?} #{@options[:]} | #{'exe/' if development?}fcom #{quote}#{search_string}#{quote} #{"--days #{days}" if days} #{'--regex' if regex_mode?} #{'--debug' if debug?} #{'--ignore-case' if ignore_case?} --path #{path_at_commit} --parse-mode --repo #{repo} COMMAND end previous_command_generated_output = false commands.each do |command| Fcom.logger.debug("Executing command: #{command}") output = `#{command}` if output.empty? previous_command_generated_output = false else if previous_command_generated_output puts("\n\n") # print blank lines for spacing end previous_command_generated_output = true puts(output) end end end |