check_debug_code 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7aab6bad16b7c529d7aea9abadfaf88754269264565310b1e061e9b18ff2064e
4
+ data.tar.gz: 5d9f3af4eeac26dc1109a9ea9eb6a742d1f61ff1d611c87431557dd63c231b35
5
+ SHA512:
6
+ metadata.gz: f7984533ff98980b51c9fb9708df31d735dbeee4f7841c33464496218a2cd7be50a01e4130d2ecc622a5810f95da6d7a1b30c8fc7f10d11ba0df39b394aff156
7
+ data.tar.gz: 32db7ad066109fdc58aba2a3f3a0c6a4493140c47e37e0206ff2b449d6253b27c5ea8b783d4133525e205f03b9f78bd5b0efdbc5781a69cffd441ebaf0dd3759
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 hataken
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # CheckDebugCode
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/check_debug_code`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/check_debug_code.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,43 @@
1
+ module CheckDebugCode
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ directory = Rails.root.to_s
9
+ matching_files = search_console_log_with_grep(directory)
10
+
11
+ # log_to_console(matching_files)
12
+ log_to_rails(matching_files)
13
+
14
+ status, headers, response = @app.call(env)
15
+ response = append_to_response_footer(response, matching_files)
16
+
17
+ [status, headers, response]
18
+ end
19
+
20
+ private
21
+
22
+ def search_console_log_with_grep(directory)
23
+ result = `grep -rl 'console.log' #{directory}`
24
+ result.split("\n")
25
+ end
26
+
27
+ # def log_to_console(matching_files)
28
+ # Rails.logger.info "<script>console.log(#{matching_files.inspect});</script>"
29
+ # end
30
+
31
+ def log_to_rails(matching_files)
32
+ Rails.logger.info "Matching files: #{matching_files.join(', ')}"
33
+ end
34
+
35
+ def append_to_response_footer(response, matching_files)
36
+ return response unless response.is_a?(Array)
37
+
38
+ response_body = response.body.join
39
+ response_body += "<footer>#{matching_files.join(', ')}</footer>"
40
+ [response_body]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module CheckDebugCode
2
+ class Railtie < ::Rails::Railtie
3
+ initializer "check_debug_code.configure_rails_initialization" do |app|
4
+ app.middleware.use CheckDebugCode::Middleware
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckDebugCode
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,3 @@
1
+ require "check_debug_code/version"
2
+ require "check_debug_code/middleware"
3
+ require "check_debug_code/railtie" if defined?(Rails)
@@ -0,0 +1,4 @@
1
+ module CheckDebugCode
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_debug_code
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - code-0wizard
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The CheckDebugCode gem searches for debug code like 'console.log' in
14
+ your Rails project every time a request is made. It outputs the filenames containing
15
+ the debug code to the browser console, view footer, and Rails logs. This helps developers
16
+ ensure that debug statements are removed from production code.
17
+ email:
18
+ - bb52119638@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/check_debug_code.rb
27
+ - lib/check_debug_code/middleware.rb
28
+ - lib/check_debug_code/railtie.rb
29
+ - lib/check_debug_code/version.rb
30
+ - sig/check_debug_code.rbs
31
+ homepage: https://github.com/veiv-veivmew/check_debug_code
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ homepage_uri: https://github.com/veiv-veivmew/check_debug_code
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 3.0.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.5.9
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: A gem to check for debug code in Rails projects.
55
+ test_files: []