grepfruit 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e88618b796ae6c0d9f54ec4bc64033e44ecee9fef5a3a889a0585dff11741e4
4
- data.tar.gz: 1d6acc4c77b5175b9d13b3c4eb23b8ed069caf6f8e031037a1ec0244d945fa5c
3
+ metadata.gz: 9c4d580e130902313d154cc1584dcc1a610252638678dcbb05f6010226987bf9
4
+ data.tar.gz: e0814d3764457e9386b3c5850cb82719cfa6dd580016ce213ef4ddb3fd76d310
5
5
  SHA512:
6
- metadata.gz: 1690b2abec8f59847eace9a70cbaa9d8b08c54d64e35b76ef5d8f2ce6c707478a044e40fad514932f2bbcd9ec2cd289129e05b47497b102ab83fa6ed78dd631b
7
- data.tar.gz: 322537a62dbb5d81731af9d973f8b5e69dc557e0721cfabbd8add2da69712b88a231371d5842b2e710fa882b7d03c9e7fd3ed9dfc4a3a5422c893ce0b9f21050
6
+ metadata.gz: b73b3561372a4f7fe6a86d7b38de4b618fd1a5b730883bbe6ad338035a8a44c1c6788fee5d3202cde8d78c9d8ee4bd9d3ec65251f92dfae3fa5d4a06a1634df0
7
+ data.tar.gz: 8772fcef03d57c21a9dea7e7135027c878e351f9d58b221d7c831435064035c7ce93cb0bac20be43051a6edcb2d5778dbf4040dc3709f3e1a9b53e3f2b826496
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v2.0.2
2
+
3
+ - Replaced `git ls-files` with `Dir.glob` in gemspec for improved portability and compatibility
4
+
5
+ ## v2.0.1
6
+
7
+ - Enhanced output to include the number of files with matches
8
+
1
9
  ## v2.0.0
2
10
 
3
11
  - Added support for Ruby 3.4
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Grepfruit is a Ruby gem for searching files within a directory for a specified regular expression pattern, with options to exclude certain files or directories from the search and colorized output for better readability.
7
7
 
8
- <img width="440" alt="Screenshot 2024-08-16 at 21 17 25" src="https://github.com/user-attachments/assets/3caaa1f4-5636-4ca1-ae45-6fc56f8945e4">
8
+ <img width="431" alt="Screenshot 2024-12-26 at 18 01 39" src="https://github.com/user-attachments/assets/e3fdb4f7-c4d9-4c8d-9a5a-228f2be55d52" />
9
9
 
10
10
  Grepfruit was originally created to be used in CI/CD pipelines to search for `TODO` comments in Ruby on Rails applications and provide more user-friendly output than the standard `grep` command, but it is flexible enough to be used for other similar purposes as well.
11
11
 
@@ -14,7 +14,7 @@ Grepfruit was originally created to be used in CI/CD pipelines to search for `TO
14
14
  Add this line to your application's Gemfile:
15
15
 
16
16
  ```ruby
17
- gem 'grepfruit'
17
+ gem "grepfruit"
18
18
  ```
19
19
 
20
20
  And then execute:
data/grepfruit.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.files = [
17
17
  "grepfruit.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"
18
- ] + `git ls-files | grep -E '^(lib|exe)'`.split("\n")
18
+ ] + Dir.glob("{exe,lib}/**/*")
19
19
 
20
20
  spec.bindir = "exe"
21
21
  spec.executables = ["grepfruit"]
@@ -1,3 +1,3 @@
1
1
  module Grepfruit
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.2"
3
3
  end
data/lib/search.rb CHANGED
@@ -3,11 +3,6 @@ require "find"
3
3
 
4
4
  module Grepfruit
5
5
  class Search
6
- CYAN = "\e[36m"
7
- RED = "\e[31m"
8
- GREEN = "\e[32m"
9
- RESET = "\e[0m"
10
-
11
6
  attr_reader :dir, :regex, :excluded_paths, :excluded_lines, :truncate, :search_hidden
12
7
 
13
8
  def initialize(dir:, regex:, exclude:, truncate:, search_hidden:)
@@ -19,48 +14,65 @@ module Grepfruit
19
14
  end
20
15
 
21
16
  def run
22
- lines, files = [], 0
17
+ lines, files, files_with_matches = [], 0, 0
23
18
 
24
19
  puts "Searching for #{regex.inspect} in #{dir.inspect}...\n\n"
25
20
 
26
21
  Find.find(dir) do |path|
27
- Find.prune if excluded_path?(path) || !search_hidden && hidden?(path)
22
+ Find.prune if excluded_path?(path)
28
23
 
29
- next if File.directory?(path) || File.symlink?(path)
24
+ next if not_searchable?(path)
30
25
 
31
26
  files += 1
27
+ match = process_file(path, lines)
28
+
29
+ if match
30
+ files_with_matches += 1
31
+ print "#{COLORS[:red]}M#{COLORS[:reset]}"
32
+ else
33
+ print "#{COLORS[:green]}.#{COLORS[:reset]}"
34
+ end
35
+ end
32
36
 
33
- match = false
37
+ display_results(lines, files, files_with_matches)
38
+ end
34
39
 
35
- File.foreach(path).with_index do |line, line_num|
36
- next unless line.valid_encoding?
40
+ COLORS = { cyan: "\e[36m", red: "\e[31m", green: "\e[32m", reset: "\e[0m" }
41
+ private_constant :COLORS
37
42
 
38
- if line.match?(regex) && !excluded_line?(path, line_num)
39
- lines << "#{CYAN}#{relative_path_with_line_num(path, line_num)}#{RESET}: #{processed_line(line)}"
40
- match = true
41
- end
42
- end
43
+ private
43
44
 
44
- print match ? "#{RED}M#{RESET}" : "#{GREEN}.#{RESET}"
45
+ def not_searchable?(path)
46
+ File.directory?(path) || File.symlink?(path)
47
+ end
48
+
49
+ def process_file(path, lines)
50
+ lines_size = lines.size
51
+
52
+ File.foreach(path).with_index do |line, line_num|
53
+ next if !line.valid_encoding? || !line.match?(regex) || excluded_line?(path, line_num)
54
+
55
+ lines << "#{COLORS[:cyan]}#{relative_path_with_line_num(path, line_num)}#{COLORS[:reset]}: #{processed_line(line)}"
45
56
  end
46
57
 
58
+ lines.size > lines_size
59
+ end
60
+
61
+ def display_results(lines, files, files_with_matches)
47
62
  puts "\n\n" if files.positive?
48
63
 
49
64
  if lines.empty?
50
- puts "#{number_of_files(files)} checked, #{GREEN}no matches found#{RESET}"
65
+ puts "#{number_of_files(files)} checked, #{COLORS[:green]}no matches found#{COLORS[:reset]}"
51
66
  exit(0)
52
67
  else
53
- puts "Matches:\n\n"
54
- puts "#{lines.join("\n")}\n\n"
55
- puts "#{number_of_files(files)} checked, #{RED}#{number_of_matches(lines.size)} found#{RESET}"
68
+ puts "Matches:\n\n#{lines.join("\n")}\n\n"
69
+ puts "#{number_of_files(files)} checked, #{COLORS[:red]}#{number_of_matches(lines.size)} found in #{number_of_files(files_with_matches)}#{COLORS[:reset]}"
56
70
  exit(1)
57
71
  end
58
72
  end
59
73
 
60
- private
61
-
62
74
  def excluded_path?(path)
63
- excluded?(excluded_paths, relative_path(path))
75
+ excluded?(excluded_paths, relative_path(path)) || !search_hidden && hidden?(path)
64
76
  end
65
77
 
66
78
  def excluded_line?(path, line_num)
metadata CHANGED
@@ -1,17 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grepfruit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-25 00:00:00.000000000 Z
10
+ date: 2025-02-21 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
- email:
15
12
  executables:
16
13
  - grepfruit
17
14
  extensions: []
@@ -33,7 +30,6 @@ metadata:
33
30
  source_code_uri: https://github.com/enjaku4/grepfruit
34
31
  changelog_uri: https://github.com/enjaku4/grepfruit/blob/master/CHANGELOG.md
35
32
  rubygems_mfa_required: 'true'
36
- post_install_message:
37
33
  rdoc_options: []
38
34
  require_paths:
39
35
  - lib
@@ -51,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
47
  - !ruby/object:Gem::Version
52
48
  version: '0'
53
49
  requirements: []
54
- rubygems_version: 3.3.27
55
- signing_key:
50
+ rubygems_version: 3.6.2
56
51
  specification_version: 4
57
52
  summary: A Ruby gem for searching text patterns in files with colorized output
58
53
  test_files: []