cleanio 0.1.2 → 0.1.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: ed57e0bb111c6d0b05161f098fd7494c13c5b1d3722e08f7199d4a8bbe12d162
4
- data.tar.gz: b6ca75aebe1758166ef4dc7ddd2cf5ae154bd05274a6a451893e6832817dde4d
3
+ metadata.gz: 036c8a1c4dde80a666690afad1a7627096d32c41be872b10aff0a00f8c89ac49
4
+ data.tar.gz: 023bc640786b9aa3f75267ac62452f6de89ec803bf9c155031c0cc4cdaaf3756
5
5
  SHA512:
6
- metadata.gz: 4bfc8e9e15d1c7d8ac647de328976f0acb4ee8790a50436a2ef4fcdac1f4ef40d9ef405bb5ad31c6c22405b24c7c62ab73bb1ad1d4ab4915718eab6a1f9edbf0
7
- data.tar.gz: 972814f60a30461276fca1ac7c6ee171993082ed1c908ca68b6d0c5f569ff1f9f4f93398b02e807ca3b61889e6fb56c9321ff9696856d9d18c1c6fe264f65077
6
+ metadata.gz: f2dc6bf75656154a3a3454a611df2db1f5ad5e6064bcb4415b07861e8df3548ece27074e0db066eba7bb98d5c6467708df8c2215f069b64896adbf280d038808
7
+ data.tar.gz: 3b5869730b6d131087e52d3c39ed2762c32649f5eab7251a85ad4a5cc5edde7b9fc6564035a50f59b056449404c2e709561426fd821dc3c993f5a90787e565a4
data/.rubocop.yml CHANGED
@@ -29,3 +29,6 @@ RSpec/MultipleExpectations:
29
29
  RSpec/DescribeClass:
30
30
  Exclude:
31
31
  - 'spec/cleanio/cleanio_cli_spec.rb'
32
+
33
+ RSpec/NestedGroups:
34
+ Enabled: false
data/README.md CHANGED
@@ -35,16 +35,18 @@ gem install cleanio
35
35
 
36
36
 
37
37
  ## Usage
38
- To clean up comments from a .rb file, simply run:
38
+ To clean up comments from a .rb file or directory, use the `Cleanio::Remover.clean` method. This will remove all single-line comments and inline comments from the file or directory.
39
39
 
40
40
  ```ruby
41
41
  require 'cleanio'
42
42
 
43
43
  Cleanio::Remover.clean('path/to/your_file.rb')
44
+ Cleanio::Remover.clean('path/to/your_directory')
45
+
44
46
  ```
45
47
  ### Audit Mode
46
48
 
47
- To use the audit mode, pass the `audit: true` flag to the `clean` method. This will output the file paths and lines containing comments without modifying the file.
49
+ To use the audit mode, pass the `audit: true` flag to the `clean` method. This will output the file paths and lines containing comments without modifying the files.
48
50
 
49
51
  #### Example
50
52
 
@@ -68,14 +70,16 @@ You can use Cleanio directly from the command line to clean or audit `.rb` files
68
70
  To remove comments from a file, use:
69
71
 
70
72
  ```bash
71
- cleanio -f path/to/file.rb
73
+ cleanio -p path/to/file.rb
74
+ cleanio -p path/to/directory
72
75
  ```
73
76
  #### Audit mode
74
77
 
75
78
  To run Cleanio in audit mode without modifying files, use the `--audit` flag:
76
79
 
77
80
  ```bash
78
- cleanio -f path/to/file.rb --audit
81
+ cleanio -p path/to/file.rb --audit
82
+ cleanio -p path/to/directory --audit
79
83
  ```
80
84
 
81
85
  ## Testing
@@ -114,5 +118,4 @@ The gem is available as open source under the terms of the MIT License.
114
118
  - Add support multi-line comments (`=begin`...`=end`)
115
119
  - Add support to magic comments (e.g. `# frozen_string_literal: true`) https://docs.ruby-lang.org/en/3.2/syntax/comments_rdoc.html - thanks [Chris](https://github.com/khasinski)!
116
120
  - Option to stay documentation comments (e.g. `# @param`) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation
117
- - Option to recursively clean all files in a directory
118
121
  - Option to clean all files in a directory except for a specified file
data/exe/cleanio CHANGED
@@ -8,22 +8,26 @@ options = {}
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: cleanio [options]"
10
10
 
11
- opts.on("-f", "--file FIle", "Path to .rb file") do |file|
12
- options[:file] = file
11
+ opts.on("-p", "--path PATH", "Path to a .rb file or directory") do |path|
12
+ options[:path] = path
13
13
  end
14
- opts.on("--audit", "Run in audit mode to display file paths and comment lines without modifying files") do
14
+
15
+ opts.on("--audit", "Run in audit mode to display comments without modifying files") do
15
16
  options[:audit] = true
16
17
  end
17
18
  end.parse!
18
19
 
19
- if options[:file]
20
+ if options[:path]
20
21
  begin
21
- Cleanio::Remover.clean(options[:file], audit: options[:audit])
22
- puts "Audit completed successfully." if options[:audit]
23
- puts "File cleaned successfully." unless options[:audit]
22
+ Cleanio::Remover.clean(options[:path], audit: options[:audit])
23
+ if options[:audit]
24
+ puts "Audit completed successfully."
25
+ else
26
+ puts "Cleaning completed successfully."
27
+ end
24
28
  rescue StandardError => e
25
29
  puts "Error: #{e.message}"
26
30
  end
27
31
  else
28
- puts "Please provide a file path using the -f flag."
32
+ puts "Please provide a file or directory with -p."
29
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cleanio
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/cleanio.rb CHANGED
@@ -6,8 +6,19 @@ require "ripper"
6
6
  module Cleanio
7
7
  class Remover
8
8
  def self.clean(file_path, audit: false)
9
+ if File.directory?(file_path)
10
+ Dir.glob("#{file_path}/**/*.rb").each do |file|
11
+ process_file(file, audit: audit)
12
+ end
13
+ else
14
+ process_file(file_path, audit: audit)
15
+ end
16
+ end
17
+
18
+ def self.process_file(file_path, audit: false)
9
19
  validate_file_extension(file_path)
10
20
  file_content = File.read(file_path)
21
+
11
22
  if audit
12
23
  audit_comments(file_path, file_content)
13
24
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cleanio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justyna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-15 00:00:00.000000000 Z
11
+ date: 2024-11-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: