updater_gf 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: b468868e369e146c0f3411f67229197cdc0e74e9fe998ff38a5b2935f210770b
4
+ data.tar.gz: 7d7cfea5c0665b4558aac3075aac8736598250766e51f8e2a96c86a73710c65d
5
+ SHA512:
6
+ metadata.gz: '028aab5c15effc590fb1ae02fad761a46d49eb547bc2bef1c769364d4a5522ae5bb221f1092c42dba4301e101d84016925c8cbc75bf02ab5d31fd5a91b549987'
7
+ data.tar.gz: 14a73ce98cadb8bb26ba64b40cd6dc785b6b02ef86e751efb067d2b42fc42313ffab9ad0bb9b58227f672be68392afa78d127593ae77f15dce48e1f6a3cbbc6e
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-10-23
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
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,42 @@
1
+ # UpdaterGf
2
+
3
+ UpdaterGf is a Ruby gem designed to format and beautify your Gemfile, making it cleaner and more readable.
4
+ It automatically organizes gem declarations, fixes indentation, and ensures a consistent structure throughout the file.
5
+ In addition to enhancing the Gemfile's appearance, GemfileBeautifier can also insert popular,
6
+ commonly-used gems (like pry, rspec, and rubocop) into the Gemfile, providing a streamlined development environment right out of the box.
7
+ This tool is essential for maintaining clean, professional-grade Ruby projects.
8
+
9
+ ## Installation
10
+
11
+ UpdateGf
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ bundle add updater_gf
16
+
17
+ Or Add to Gemfile and executing 'bundle install':
18
+
19
+ gem 'updater_gf'
20
+
21
+ Or If bundler is not being used to manage dependencies, install the gem by executing:
22
+
23
+ gem install updater_gf
24
+
25
+ ## Usage
26
+
27
+ after install gem
28
+
29
+ open Terminal and go to directory of project run:
30
+ $ updater_gf
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/devhoanglv92/updater_gf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/devhoanglv92/updater_gf/blob/master/CODE_OF_CONDUCT.md).
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the UpdaterGf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/updater_gf/blob/master/CODE_OF_CONDUCT.md).
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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UpdaterGf
4
+ VERSION = '0.1.0'
5
+ end
data/lib/updater_gf.rb ADDED
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "updater_gf/version"
4
+
5
+ module UpdaterGf
6
+ class Error < StandardError; end
7
+
8
+ class Updater
9
+ class << self
10
+ def find_gemfile_path
11
+ current_dir = Dir.pwd
12
+
13
+ until File.exist?(File.join(current_dir, 'Gemfile'))
14
+ parent_dir = File.expand_path('..', current_dir)
15
+ break if current_dir == parent_dir # Reached the root directory
16
+
17
+ current_dir = parent_dir
18
+ end
19
+
20
+ gemfile_path = File.join(current_dir, 'Gemfile')
21
+ raise Error, 'Gemfile not found' unless File.exist?(gemfile_path)
22
+
23
+ gemfile_path
24
+ end
25
+
26
+ def update_gemfile
27
+ gemfile_path = find_gemfile_path
28
+ content = File.read(gemfile_path)
29
+
30
+ # Replace all double quotes with single quotes
31
+ updated_content = content.gsub(/"/, "'")
32
+
33
+ final_content = update_final_content(updated_content)
34
+
35
+ File.write(gemfile_path, final_content)
36
+ end
37
+
38
+ def update_final_content(updated_content)
39
+ lines = updated_content.lines
40
+ group_test_end_index = find_group_test_end_index(lines)
41
+ return updated_content if group_test_end_index.nil?
42
+
43
+ below_group_test_lines = lines[(group_test_end_index + 1)..]
44
+ other_lines = get_other_lines(below_group_test_lines)
45
+ sorted_gem_lines = sorted_gem_lines(below_group_test_lines)
46
+ final_lines = lines[0..group_test_end_index] + other_lines + sorted_gem_lines
47
+
48
+ # Add gems from list_gems_add if not already present
49
+ final_lines += add_missing_gems(final_lines, list_gems_add)
50
+
51
+ # Sort gem lines alphabetically after adding new gems, but only those after the group :test block
52
+ final_lines = sort_gem_lines_after_test_block(final_lines, group_test_end_index)
53
+
54
+ # Add gems from list_gems_add_develop to group :development if not already present
55
+ final_lines = add_gems_to_development_group(final_lines, list_gems_add_develop)
56
+
57
+ final_lines.join
58
+ end
59
+
60
+ def find_group_test_end_index(lines)
61
+ group_test_start_index = lines.index { |line| line.strip == 'group :test do' }
62
+ return nil if group_test_start_index.nil?
63
+
64
+ group_test_end_index = lines[group_test_start_index..].index { |line| line.strip == 'end' }
65
+ return nil if group_test_end_index.nil?
66
+
67
+ group_test_start_index + group_test_end_index
68
+ end
69
+
70
+ def sorted_gem_lines(below_group_test_lines)
71
+ get_gem_lines(below_group_test_lines).sort_by { |line| line.match(/gem '([^']+)'/)[1] }
72
+ end
73
+
74
+ def get_gem_lines(below_group_test_lines)
75
+ below_group_test_lines.select { |line| line.strip.start_with?("gem '") && !line.strip.start_with?('#') }
76
+ end
77
+
78
+ def get_other_lines(below_group_test_lines)
79
+ below_group_test_lines.reject { |line| line.strip.start_with?("gem '") && !line.strip.start_with?('#') }
80
+ end
81
+
82
+ def add_missing_gems(final_lines, gems_list)
83
+ existing_gems = final_lines.select { |line| line.strip.start_with?("gem '") }.map { |line| line.match(/gem '([^']+)'/)[1] }
84
+ missing_gems = gems_list - existing_gems
85
+ missing_gems.map { |gem| "gem '#{gem}'\n" }
86
+ end
87
+
88
+ def sort_gem_lines_after_test_block(final_lines, group_test_end_index)
89
+ lines_after_test_block = final_lines[(group_test_end_index + 1)..]
90
+ gem_lines = lines_after_test_block.select { |line| line.strip.start_with?("gem '") }
91
+ other_lines = lines_after_test_block.reject { |line| line.strip.start_with?("gem '") }
92
+ sorted_gem_lines = gem_lines.sort_by { |line| line.match(/gem '([^']+)'/)[1] }
93
+ final_lines[0..group_test_end_index] + other_lines + sorted_gem_lines
94
+ end
95
+
96
+ def add_gems_to_development_group(final_lines, gems_list)
97
+ development_group_start_index = final_lines.index { |line| line.strip == 'group :development do' }
98
+ return final_lines if development_group_start_index.nil?
99
+
100
+ development_group_end_index = final_lines[development_group_start_index..].index { |line| line.strip == 'end' }
101
+ return final_lines if development_group_end_index.nil?
102
+
103
+ development_group_end_index += development_group_start_index
104
+
105
+ development_group_lines = final_lines[(development_group_start_index + 1)...development_group_end_index]
106
+ existing_gems = development_group_lines.select { |line| line.strip.start_with?("gem '") }.map { |line| line.match(/gem '([^']+)'/)[1] }
107
+ missing_gems = gems_list - existing_gems
108
+ new_gem_lines = missing_gems.map { |gem| " gem '#{gem}'\n" }
109
+
110
+ final_lines[0..development_group_start_index] +
111
+ development_group_lines +
112
+ new_gem_lines +
113
+ final_lines[development_group_end_index..]
114
+ end
115
+
116
+ def list_gems_add
117
+ %w[ransack devise pagy pundit rack-cors redis sidekiq draper paranoia active_admin]
118
+ end
119
+
120
+ def list_gems_add_develop
121
+ %w[pry letter_opener bullet better_errors binding_of_caller]
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,4 @@
1
+ module UpdaterGf
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/updater_gf/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'updater_gf'
7
+ spec.version = UpdaterGf::VERSION
8
+ spec.authors = ['devhoanglv92']
9
+ spec.email = ['devhoanglv92@gmail.com']
10
+
11
+ spec.summary = 'update Gemfile and clean code file'
12
+ spec.description = 'update Gemfile and clean code file by updater_gf'
13
+ spec.homepage = 'https://github.com/hoangdev92/updater_gf'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.6.5'
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/hoangdev92/updater_gf'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/hoangdev92/updater_gf/blob/master/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: updater_gf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - devhoanglv92
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: update Gemfile and clean code file by updater_gf
14
+ email:
15
+ - devhoanglv92@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - CODE_OF_CONDUCT.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/updater_gf.rb
26
+ - lib/updater_gf/version.rb
27
+ - sig/updater_gf.rbs
28
+ - updater_gf.gemspec
29
+ homepage: https://github.com/hoangdev92/updater_gf
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ allowed_push_host: https://rubygems.org
34
+ homepage_uri: https://github.com/hoangdev92/updater_gf
35
+ source_code_uri: https://github.com/hoangdev92/updater_gf
36
+ changelog_uri: https://github.com/hoangdev92/updater_gf/blob/master/CHANGELOG.md
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.5
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.3.7
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: update Gemfile and clean code file
56
+ test_files: []