grepfruit 2.0.2 → 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: 9c4d580e130902313d154cc1584dcc1a610252638678dcbb05f6010226987bf9
4
- data.tar.gz: e0814d3764457e9386b3c5850cb82719cfa6dd580016ce213ef4ddb3fd76d310
3
+ metadata.gz: 523ee40a32ea4bc5c0d6b91ca60d147985a8d79b84396b17c3fd4b49f629f121
4
+ data.tar.gz: 84ee19de06fbb489a6dc9ac32365cc92a00b23fe11337b7d2c236f12ffa509c0
5
5
  SHA512:
6
- metadata.gz: b73b3561372a4f7fe6a86d7b38de4b618fd1a5b730883bbe6ad338035a8a44c1c6788fee5d3202cde8d78c9d8ee4bd9d3ec65251f92dfae3fa5d4a06a1634df0
7
- data.tar.gz: 8772fcef03d57c21a9dea7e7135027c878e351f9d58b221d7c831435064035c7ce93cb0bac20be43051a6edcb2d5778dbf4040dc3709f3e1a9b53e3f2b826496
6
+ metadata.gz: 76821e2d3b8967d931491d66c7d25cbea24b8998d9c4d2603c13a8597c04484d6eb0cb046e5ad9470d9c546ca70ec729b3929447db66dbf7ccceba3767393575
7
+ data.tar.gz: 766456777c31d8c58a4e2ee6d4f6891ac8c280130c9c671894dd56d6e7e1c64e65ad512f0a73497ac6f94ab19653a7267d394fea152aca9a451cbfa874754e83
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v2.0.3
2
+
3
+ - Updated gemspec metadata to include the correct homepage URL
4
+
1
5
  ## v2.0.2
2
6
 
3
7
  - Replaced `git ls-files` with `Dir.glob` in gemspec for improved portability and compatibility
data/README.md CHANGED
@@ -1,7 +1,7 @@
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
 
@@ -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"
@@ -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.2"
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,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grepfruit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-21 00:00:00.000000000 Z
10
+ date: 2025-05-16 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  executables:
13
13
  - grepfruit
@@ -20,15 +20,16 @@ files:
20
20
  - exe/grepfruit
21
21
  - grepfruit.gemspec
22
22
  - lib/grepfruit.rb
23
+ - lib/grepfruit/decorator.rb
24
+ - lib/grepfruit/search.rb
23
25
  - lib/grepfruit/version.rb
24
- - lib/search.rb
25
- homepage: https://github.com/enjaku4/grepfruit
26
+ homepage: https://github.com/brownboxdev/grepfruit
26
27
  licenses:
27
28
  - MIT
28
29
  metadata:
29
- homepage_uri: https://github.com/enjaku4/grepfruit
30
- source_code_uri: https://github.com/enjaku4/grepfruit
31
- 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
32
33
  rubygems_mfa_required: 'true'
33
34
  rdoc_options: []
34
35
  require_paths: