grepfruit 2.0.1 → 2.0.3

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: 96acccb252509097d33a932f2d463358358d1ee20aea951561e94c7aed2e995d
4
- data.tar.gz: 1dd758ab6f2fef47cea4890cf8fe09ed4f31cd5477d04e0be9891614ed605457
3
+ metadata.gz: 523ee40a32ea4bc5c0d6b91ca60d147985a8d79b84396b17c3fd4b49f629f121
4
+ data.tar.gz: 84ee19de06fbb489a6dc9ac32365cc92a00b23fe11337b7d2c236f12ffa509c0
5
5
  SHA512:
6
- metadata.gz: '02887d74be8c339a488626d15d53fc8609b5ec8b6ec68396d988b30d5bd147e1f643d6dc07bfdb75a71db40f4c18e5d40e556ea464814664ff8dcfa676fb5beb'
7
- data.tar.gz: 17d41be73711460f8da710759850b53f2d622d5a03442e00521123c2c0c964e01effdb93e97a768e5d75db33d4087ec03a64a42d4466f462d4d5a65e4def5b2c
6
+ metadata.gz: 76821e2d3b8967d931491d66c7d25cbea24b8998d9c4d2603c13a8597c04484d6eb0cb046e5ad9470d9c546ca70ec729b3929447db66dbf7ccceba3767393575
7
+ data.tar.gz: 766456777c31d8c58a4e2ee6d4f6891ac8c280130c9c671894dd56d6e7e1c64e65ad512f0a73497ac6f94ab19653a7267d394fea152aca9a451cbfa874754e83
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v2.0.3
2
+
3
+ - Updated gemspec metadata to include the correct homepage URL
4
+
5
+ ## v2.0.2
6
+
7
+ - Replaced `git ls-files` with `Dir.glob` in gemspec for improved portability and compatibility
8
+
1
9
  ## v2.0.1
2
10
 
3
11
  - Enhanced output to include the number of files with matches
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Grepfruit
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/grepfruit.svg)](http://badge.fury.io/rb/grepfruit)
4
- [![Github Actions badge](https://github.com/enjaku4/grepfruit/actions/workflows/main.yml/badge.svg)](https://github.com/enjaku4/grepfruit/actions/workflows/main.yml)
4
+ [![Github Actions badge](https://github.com/brownboxdev/grepfruit/actions/workflows/ci.yml/badge.svg)](https://github.com/brownboxdev/grepfruit/actions/workflows/ci.yml)
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:
@@ -91,12 +91,12 @@ Encountered a bug?
91
91
 
92
92
  ## Contributing
93
93
 
94
- Before creating an issue or a pull request, please read the [contributing guidelines](https://github.com/enjaku4/grepfruit/blob/master/CONTRIBUTING.md).
94
+ Before creating an issue or a pull request, please read the [contributing guidelines](https://github.com/brownboxdev/grepfruit/blob/master/CONTRIBUTING.md).
95
95
 
96
96
  ## License
97
97
 
98
- The gem is available as open source under the terms of the [MIT License](https://github.com/enjaku4/grepfruit/blob/master/LICENSE.txt).
98
+ The gem is available as open source under the terms of the [MIT License](https://github.com/brownboxdev/grepfruit/blob/master/LICENSE.txt).
99
99
 
100
100
  ## Code of Conduct
101
101
 
102
- Everyone interacting in the Grepfruit project is expected to follow the [code of conduct](https://github.com/enjaku4/grepfruit/blob/master/CODE_OF_CONDUCT.md).
102
+ Everyone interacting in the Grepfruit project is expected to follow the [code of conduct](https://github.com/brownboxdev/grepfruit/blob/master/CODE_OF_CONDUCT.md).
data/grepfruit.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "grepfruit"
5
5
  spec.version = Grepfruit::VERSION
6
6
  spec.authors = ["enjaku4"]
7
- spec.homepage = "https://github.com/enjaku4/grepfruit"
7
+ spec.homepage = "https://github.com/brownboxdev/grepfruit"
8
8
  spec.metadata["homepage_uri"] = spec.homepage
9
9
  spec.metadata["source_code_uri"] = spec.homepage
10
10
  spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
@@ -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"]
@@ -0,0 +1,58 @@
1
+ module Grepfruit
2
+ module Decorator
3
+ COLORS = { cyan: "\e[36m", red: "\e[31m", green: "\e[32m", reset: "\e[0m" }
4
+ private_constant :COLORS
5
+
6
+ private
7
+
8
+ def green(text)
9
+ "#{COLORS[:green]}#{text}#{COLORS[:reset]}"
10
+ end
11
+
12
+ def red(text)
13
+ "#{COLORS[:red]}#{text}#{COLORS[:reset]}"
14
+ end
15
+
16
+ def cyan(text)
17
+ "#{COLORS[:cyan]}#{text}#{COLORS[:reset]}"
18
+ end
19
+
20
+ def number_of_files(num)
21
+ "#{num} file#{'s' if num > 1}"
22
+ end
23
+
24
+ def number_of_matches(num)
25
+ "#{num} match#{'es' if num > 1}"
26
+ end
27
+
28
+ def relative_path(path)
29
+ Pathname.new(path).relative_path_from(Pathname.new(dir)).to_s
30
+ end
31
+
32
+ def relative_path_with_line_num(path, line_num)
33
+ "#{relative_path(path)}:#{line_num + 1}"
34
+ end
35
+
36
+ def processed_line(line)
37
+ stripped_line = line.strip
38
+ truncate && stripped_line.length > truncate ? "#{stripped_line[0..truncate - 1]}..." : stripped_line
39
+ end
40
+
41
+ def decorated_line(path, line_num, line)
42
+ "#{cyan(relative_path_with_line_num(path, line_num))}: #{processed_line(line)}"
43
+ end
44
+
45
+ def display_results(lines, files, files_with_matches)
46
+ puts "\n\n" if files.positive?
47
+
48
+ if lines.empty?
49
+ puts "#{number_of_files(files)} checked, #{green('no matches found')}"
50
+ exit(0)
51
+ else
52
+ puts "Matches:\n\n#{lines.join("\n")}\n\n"
53
+ puts "#{number_of_files(files)} checked, #{red("#{number_of_matches(lines.size)} found in #{number_of_files(files_with_matches)}")}"
54
+ exit(1)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,8 +1,12 @@
1
1
  require "pathname"
2
2
  require "find"
3
3
 
4
+ require_relative "decorator"
5
+
4
6
  module Grepfruit
5
7
  class Search
8
+ include Decorator
9
+
6
10
  attr_reader :dir, :regex, :excluded_paths, :excluded_lines, :truncate, :search_hidden
7
11
 
8
12
  def initialize(dir:, regex:, exclude:, truncate:, search_hidden:)
@@ -28,18 +32,15 @@ module Grepfruit
28
32
 
29
33
  if match
30
34
  files_with_matches += 1
31
- print "#{COLORS[:red]}M#{COLORS[:reset]}"
35
+ print red("M")
32
36
  else
33
- print "#{COLORS[:green]}.#{COLORS[:reset]}"
37
+ print green(".")
34
38
  end
35
39
  end
36
40
 
37
41
  display_results(lines, files, files_with_matches)
38
42
  end
39
43
 
40
- COLORS = { cyan: "\e[36m", red: "\e[31m", green: "\e[32m", reset: "\e[0m" }
41
- private_constant :COLORS
42
-
43
44
  private
44
45
 
45
46
  def not_searchable?(path)
@@ -52,25 +53,12 @@ module Grepfruit
52
53
  File.foreach(path).with_index do |line, line_num|
53
54
  next if !line.valid_encoding? || !line.match?(regex) || excluded_line?(path, line_num)
54
55
 
55
- lines << "#{COLORS[:cyan]}#{relative_path_with_line_num(path, line_num)}#{COLORS[:reset]}: #{processed_line(line)}"
56
+ lines << decorated_line(path, line_num, line)
56
57
  end
57
58
 
58
59
  lines.size > lines_size
59
60
  end
60
61
 
61
- def display_results(lines, files, files_with_matches)
62
- puts "\n\n" if files.positive?
63
-
64
- if lines.empty?
65
- puts "#{number_of_files(files)} checked, #{COLORS[:green]}no matches found#{COLORS[:reset]}"
66
- exit(0)
67
- else
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]}"
70
- exit(1)
71
- end
72
- end
73
-
74
62
  def excluded_path?(path)
75
63
  excluded?(excluded_paths, relative_path(path)) || !search_hidden && hidden?(path)
76
64
  end
@@ -83,29 +71,8 @@ module Grepfruit
83
71
  list.any? { path.split("/").last(_1.length) == _1 }
84
72
  end
85
73
 
86
- def relative_path(path)
87
- Pathname.new(path).relative_path_from(Pathname.new(dir)).to_s
88
- end
89
-
90
- def relative_path_with_line_num(path, line_num)
91
- "#{relative_path(path)}:#{line_num + 1}"
92
- end
93
-
94
- def processed_line(line)
95
- stripped_line = line.strip
96
- truncate && stripped_line.length > truncate ? "#{stripped_line[0..truncate - 1]}..." : stripped_line
97
- end
98
-
99
74
  def hidden?(path)
100
75
  File.basename(path).start_with?(".")
101
76
  end
102
-
103
- def number_of_files(num)
104
- "#{num} file#{'s' if num > 1}"
105
- end
106
-
107
- def number_of_matches(num)
108
- "#{num} match#{'es' if num > 1}"
109
- end
110
77
  end
111
78
  end
@@ -1,3 +1,3 @@
1
1
  module Grepfruit
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.3"
3
3
  end
data/lib/grepfruit.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require_relative "grepfruit/version"
2
- require_relative "search"
2
+ require_relative "grepfruit/search"
3
3
 
4
4
  module Grepfruit
5
5
  class Error < StandardError; end
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.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-26 00:00:00.000000000 Z
10
+ date: 2025-05-16 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
- email:
15
12
  executables:
16
13
  - grepfruit
17
14
  extensions: []
@@ -23,17 +20,17 @@ files:
23
20
  - exe/grepfruit
24
21
  - grepfruit.gemspec
25
22
  - lib/grepfruit.rb
23
+ - lib/grepfruit/decorator.rb
24
+ - lib/grepfruit/search.rb
26
25
  - lib/grepfruit/version.rb
27
- - lib/search.rb
28
- homepage: https://github.com/enjaku4/grepfruit
26
+ homepage: https://github.com/brownboxdev/grepfruit
29
27
  licenses:
30
28
  - MIT
31
29
  metadata:
32
- homepage_uri: https://github.com/enjaku4/grepfruit
33
- source_code_uri: https://github.com/enjaku4/grepfruit
34
- changelog_uri: https://github.com/enjaku4/grepfruit/blob/master/CHANGELOG.md
30
+ homepage_uri: https://github.com/brownboxdev/grepfruit
31
+ source_code_uri: https://github.com/brownboxdev/grepfruit
32
+ changelog_uri: https://github.com/brownboxdev/grepfruit/blob/master/CHANGELOG.md
35
33
  rubygems_mfa_required: 'true'
36
- post_install_message:
37
34
  rdoc_options: []
38
35
  require_paths:
39
36
  - lib
@@ -51,8 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
48
  - !ruby/object:Gem::Version
52
49
  version: '0'
53
50
  requirements: []
54
- rubygems_version: 3.3.27
55
- signing_key:
51
+ rubygems_version: 3.6.2
56
52
  specification_version: 4
57
53
  summary: A Ruby gem for searching text patterns in files with colorized output
58
54
  test_files: []