gem_sorter 0.4.1 → 0.5.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 +4 -4
- data/README.md +34 -4
- data/lib/gem_sorter/version.rb +1 -1
- data/lib/gem_sorter.rb +17 -1
- data/lib/task_config.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fd0cee6472698ca2168aa26c7db2524a0c678cdb0b4270010653026d5729e7
|
4
|
+
data.tar.gz: 3a9760914476b821fc87a3cb15293b7d90ebb6b3044b37520d4fb078d634b4ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4aaa1957dc88ff452f8d799aaa0468646e5f11972975edadf04c3f75f41efd3a620d28fbdc76b56140ded25e99a9be619b6281c521706315ea0a49858a7f1e9
|
7
|
+
data.tar.gz: 8b8a3eed7eba14a635b7153c2dbc4534161763d4a8db999110e55346b5b586aebf1eac692eaf928c1bacd1bdb584c68153eefa28110c142f90e2e986d36f606a
|
data/README.md
CHANGED
@@ -13,6 +13,7 @@ GemSorter is a simple gem to sort the contents of your Gemfile alphabetically wh
|
|
13
13
|
* Optionally creates a backup of the original Gemfile.
|
14
14
|
* Update the comments of the gems based on their descriptions.
|
15
15
|
* Optionally converts single quotes to double quotes in gem declarations.
|
16
|
+
* Optionally removes version constraints from gems while preserving other parameters.
|
16
17
|
|
17
18
|
## Installation
|
18
19
|
Add the gem to your project's `Gemfile`:
|
@@ -44,13 +45,14 @@ rake -r gem_sorter gemfile:sort
|
|
44
45
|
* `update_comments`: Pass `true` to update the comments of the gems based on their descriptions.
|
45
46
|
* `update_versions`: Pass `true` to update the versions of the gems based on the lockfile.
|
46
47
|
* `use_double_quotes`: Pass `true` to convert single quotes to double quotes in gem declarations.
|
48
|
+
* `remove_versions`: Pass `true` to remove version constraints from gems while preserving other parameters like `require` or `platforms`. This option takes precedence over `update_versions` if both are enabled.
|
47
49
|
|
48
50
|
Example:
|
49
51
|
|
50
52
|
```bash
|
51
|
-
rake gemfile:sort[true,true,true,true]
|
53
|
+
rake gemfile:sort[true,true,true,true,true]
|
52
54
|
```
|
53
|
-
This will sort your Gemfile, create a backup, update comments and versions,
|
55
|
+
This will sort your Gemfile, create a backup, update comments and versions, convert single quotes to double quotes, and remove version constraints.
|
54
56
|
|
55
57
|
### Options File
|
56
58
|
Create a file in the root of your project called `gem_sorter.yml`
|
@@ -58,6 +60,7 @@ Create a file in the root of your project called `gem_sorter.yml`
|
|
58
60
|
* `update_comments`: Pass `true` to update the comments of the gems based on their descriptions.
|
59
61
|
* `update_versions`: Pass `true` to update the versions of the gems based on the lockfile.
|
60
62
|
* `use_double_quotes`: Pass `true` to convert single quotes to double quotes in gem declarations.
|
63
|
+
* `remove_versions`: Pass `true` to remove version constraints from gems while preserving other parameters like `require` or `platforms`. This option takes precedence over `update_versions` if both are enabled.
|
61
64
|
* `ignore_gems`: Pass an array of GEMs you want to ignore versions and comments
|
62
65
|
* `ignore_gem_versions`: Pass an array of GEMs you want to ignore versions
|
63
66
|
* `ignore_gem_comments`: Pass an array of GEMs you want to ignore comments
|
@@ -69,6 +72,7 @@ backup: true
|
|
69
72
|
update_comments: true
|
70
73
|
update_versions: false
|
71
74
|
use_double_quotes: true
|
75
|
+
remove_versions: true
|
72
76
|
ignore_gems:
|
73
77
|
- byebug
|
74
78
|
- discard
|
@@ -77,7 +81,7 @@ ignore_gem_versions:
|
|
77
81
|
ignore_gem_comments:
|
78
82
|
- otpor
|
79
83
|
```
|
80
|
-
This will sort your Gemfile, create a backup, update comments, and ignore specific gems for different operations.
|
84
|
+
This will sort your Gemfile, create a backup, update comments, remove version constraints, and ignore specific gems for different operations.
|
81
85
|
|
82
86
|
## Example
|
83
87
|
### Input Gemfile
|
@@ -87,6 +91,9 @@ source "https://rubygems.org"
|
|
87
91
|
# Framework
|
88
92
|
gem "rails"
|
89
93
|
gem "puma", "~> 5.3"
|
94
|
+
gem "thruster", "~> 0.1.13", require: false
|
95
|
+
gem "countries", "~> 7.1", ">= 7.1.1"
|
96
|
+
gem "tzinfo-data", platforms: %i[ windows jruby ]
|
90
97
|
|
91
98
|
group :development do
|
92
99
|
gem "dotenv-rails"
|
@@ -102,10 +109,33 @@ source "https://rubygems.org"
|
|
102
109
|
gem "puma", "~> 5.3"
|
103
110
|
# Full-stack web application framework.
|
104
111
|
gem "rails", "~> 8.0", ">= 8.0.1"
|
112
|
+
gem "thruster", "~> 0.1.13", require: false
|
113
|
+
gem "countries", "~> 7.1", ">= 7.1.1"
|
114
|
+
gem "tzinfo-data", platforms: %i[ windows jruby ]
|
105
115
|
|
106
116
|
group :development do
|
107
117
|
# Autoload dotenv in Rails.
|
108
|
-
gem
|
118
|
+
gem "dotenv-rails", "~> 3.1", ">= 3.1.7"
|
119
|
+
# A runtime developer console and IRB alternative with powerful introspection capabilities.
|
120
|
+
gem "pry"
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
### Output Gemfile (with remove_versions: true)
|
125
|
+
```ruby
|
126
|
+
source "https://rubygems.org"
|
127
|
+
|
128
|
+
# A Ruby/Rack web server built for parallelism.
|
129
|
+
gem "puma"
|
130
|
+
# Full-stack web application framework.
|
131
|
+
gem "rails"
|
132
|
+
gem "thruster", require: false
|
133
|
+
gem "countries"
|
134
|
+
gem "tzinfo-data", platforms: %i[ windows jruby ]
|
135
|
+
|
136
|
+
group :development do
|
137
|
+
# Autoload dotenv in Rails.
|
138
|
+
gem "dotenv-rails"
|
109
139
|
# A runtime developer console and IRB alternative with powerful introspection capabilities.
|
110
140
|
gem "pry"
|
111
141
|
end
|
data/lib/gem_sorter/version.rb
CHANGED
data/lib/gem_sorter.rb
CHANGED
@@ -22,7 +22,7 @@ module GemSorter
|
|
22
22
|
|
23
23
|
update_gem_summaries(gems) if @config.update_comments
|
24
24
|
update_version_text(gems) if @config.update_versions
|
25
|
-
|
25
|
+
remove_versions(gems) if @config.remove_versions
|
26
26
|
sorted_gems = sort_gem_blocks(gems)
|
27
27
|
|
28
28
|
result = []
|
@@ -35,6 +35,7 @@ module GemSorter
|
|
35
35
|
group_gems = process_group_section(section)
|
36
36
|
update_gem_summaries(group_gems) if @config.update_comments
|
37
37
|
update_version_text(group_gems) if @config.update_versions
|
38
|
+
remove_versions(group_gems) if @config.remove_versions
|
38
39
|
result << "group#{section.split("\n").first}"
|
39
40
|
result.concat(sort_gem_blocks(group_gems).map { |line| " #{line}" })
|
40
41
|
result << 'end'
|
@@ -99,6 +100,21 @@ module GemSorter
|
|
99
100
|
end
|
100
101
|
end
|
101
102
|
|
103
|
+
def remove_versions(gems)
|
104
|
+
gems.each do |gem_block|
|
105
|
+
gem_name = extract_gem_name(gem_block[:gem_line])
|
106
|
+
next if @config.ignore_gems.include?(gem_name) || @config.ignore_gem_versions.include?(gem_name)
|
107
|
+
|
108
|
+
extra_params = extract_params(gem_block[:gem_line])
|
109
|
+
base = gem_block[:gem_line].match(/gem\s+['"][^'"]+['"]/)[0]
|
110
|
+
if extra_params
|
111
|
+
gem_block[:gem_line] = "#{base},#{extra_params}"
|
112
|
+
else
|
113
|
+
gem_block[:gem_line] = base
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
102
118
|
def extract_params(gem_line)
|
103
119
|
return nil unless gem_line =~ /gem\s+['"][^'"]+['"]/
|
104
120
|
|
data/lib/task_config.rb
CHANGED
@@ -9,6 +9,7 @@ module GemSorter
|
|
9
9
|
'update_comments' => false,
|
10
10
|
'update_versions' => false,
|
11
11
|
'use_double_quotes' => false,
|
12
|
+
'remove_versions' => false,
|
12
13
|
'gemfile_path' => 'Gemfile',
|
13
14
|
'ignore_gems' => [],
|
14
15
|
'ignore_gem_versions' => [],
|
@@ -20,6 +21,7 @@ module GemSorter
|
|
20
21
|
@update_comments = nil
|
21
22
|
@update_versions = nil
|
22
23
|
@use_double_quotes = nil
|
24
|
+
@remove_versions = nil
|
23
25
|
@ignore_gems = nil
|
24
26
|
@ignore_gem_versions = nil
|
25
27
|
@ignore_gem_comments = nil
|
@@ -43,6 +45,10 @@ module GemSorter
|
|
43
45
|
@use_double_quotes.nil? ? DEFAULT_CONFIG['use_double_quotes'] : @use_double_quotes
|
44
46
|
end
|
45
47
|
|
48
|
+
def remove_versions
|
49
|
+
@remove_versions.nil? ? DEFAULT_CONFIG['remove_versions'] : @remove_versions
|
50
|
+
end
|
51
|
+
|
46
52
|
def ignore_gems
|
47
53
|
@ignore_gems.nil? ? DEFAULT_CONFIG['ignore_gems'] : @ignore_gems
|
48
54
|
end
|
@@ -75,6 +81,7 @@ module GemSorter
|
|
75
81
|
@update_versions = task_config['update_versions'] if task_config.key?('update_versions')
|
76
82
|
@gemfile_path = task_config['gemfile_path'] if task_config.key?('gemfile_path')
|
77
83
|
@use_double_quotes = task_config['use_double_quotes'] if task_config.key?('use_double_quotes')
|
84
|
+
@remove_versions = task_config['remove_versions'] if task_config.key?('remove_versions')
|
78
85
|
@ignore_gems = task_config['ignore_gems'] if task_config.key?('ignore_gems')
|
79
86
|
@ignore_gem_versions = task_config['ignore_gem_versions'] if task_config.key?('ignore_gem_versions')
|
80
87
|
@ignore_gem_comments = task_config['ignore_gem_comments'] if task_config.key?('ignore_gem_comments')
|
@@ -88,6 +95,7 @@ module GemSorter
|
|
88
95
|
@update_versions = parse_boolean(args[:update_versions]) unless args[:update_versions].nil?
|
89
96
|
@gemfile_path = args[:gemfile_path] unless args[:gemfile_path].nil?
|
90
97
|
@use_double_quotes = parse_boolean(args[:use_double_quotes]) unless args[:use_double_quotes].nil?
|
98
|
+
@remove_versions = parse_boolean(args[:remove_versions]) unless args[:remove_versions].nil?
|
91
99
|
@ignore_gems = args[:ignore_gems] unless args[:ignore_gems].nil?
|
92
100
|
@ignore_gem_versions = args[:ignore_gem_versions] unless args[:ignore_gem_versions].nil?
|
93
101
|
@ignore_gem_comments = args[:ignore_gem_comments] unless args[:ignore_gem_comments].nil?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_sorter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renan Garcia
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.6.
|
73
|
+
rubygems_version: 3.6.7
|
74
74
|
specification_version: 4
|
75
75
|
summary: Sort gems in the Gemfile alphabetically
|
76
76
|
test_files: []
|