gem_sorter 0.3.2 → 0.4.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 +19 -3
- data/lib/gem_sorter/version.rb +1 -1
- data/lib/gem_sorter.rb +38 -0
- data/lib/task_config.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8a4c3e034c1034831bb4e5c86a019d920709d36307496ba289319d342dc1b25
|
4
|
+
data.tar.gz: 05c3b4da42d06f1dd763c3aacda058e44961bdf2c7e51003ebf9cf907b52e549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e39b95e825eee0956bd92f0b02a70acdf4ac9b3bfac1f12b490db6b79c73814ab7dfbb382dd87a611a4236dd6461979015c141569622d0becb66ec992827b13e
|
7
|
+
data.tar.gz: 0f0e81fee4d454db0236c0b60babd45793efc6511aec24a37334f075389a3b8a92db00f9f002bc8bef336051529193780c6c9c238196a2d7ee93a53195d56fad
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ GemSorter is a simple gem to sort the contents of your Gemfile alphabetically wh
|
|
12
12
|
* Maintains group structure in the Gemfile.
|
13
13
|
* Optionally creates a backup of the original Gemfile.
|
14
14
|
* Update the comments of the gems based on their descriptions.
|
15
|
+
* Optionally converts single quotes to double quotes in gem declarations.
|
15
16
|
|
16
17
|
## Installation
|
17
18
|
Add the gem to your project's `Gemfile`:
|
@@ -19,6 +20,11 @@ Add the gem to your project's `Gemfile`:
|
|
19
20
|
```ruby
|
20
21
|
gem "gem_sorter"
|
21
22
|
```
|
23
|
+
or install it globally:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
gem install gem_sorter
|
27
|
+
```
|
22
28
|
|
23
29
|
## Usage
|
24
30
|
Once installed, you can use the provided Rake task to sort your Gemfile:
|
@@ -27,23 +33,31 @@ Once installed, you can use the provided Rake task to sort your Gemfile:
|
|
27
33
|
rake gemfile:sort
|
28
34
|
```
|
29
35
|
|
36
|
+
You can also run the gem_sorter globally, without needing to add it to your Gemfile:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
rake -r gem_sorter gemfile:sort
|
40
|
+
```
|
41
|
+
|
30
42
|
### Options
|
31
43
|
* `backup`: Pass `true` to create a backup of your Gemfile as `Gemfile.old` before sorting.
|
32
44
|
* `update_comments`: Pass `true` to update the comments of the gems based on their descriptions.
|
33
45
|
* `update_versions`: Pass `true` to update the versions of the gems based on the lockfile.
|
46
|
+
* `use_double_quotes`: Pass `true` to convert single quotes to double quotes in gem declarations.
|
34
47
|
|
35
48
|
Example:
|
36
49
|
|
37
50
|
```bash
|
38
|
-
rake gemfile:sort[true,true,true]
|
51
|
+
rake gemfile:sort[true,true,true,true]
|
39
52
|
```
|
40
|
-
This will sort your Gemfile, create a backup,
|
53
|
+
This will sort your Gemfile, create a backup, update comments and versions, and convert single quotes to double quotes.
|
41
54
|
|
42
55
|
### Options File
|
43
56
|
Create a file in the root of your project called `gem_sorter.yml`
|
44
57
|
* `backup`: Pass `true` to create a backup of your Gemfile as `Gemfile.old` before sorting.
|
45
58
|
* `update_comments`: Pass `true` to update the comments of the gems based on their descriptions.
|
46
59
|
* `update_versions`: Pass `true` to update the versions of the gems based on the lockfile.
|
60
|
+
* `use_double_quotes`: Pass `true` to convert single quotes to double quotes in gem declarations.
|
47
61
|
* `ignore_gems`: Pass an array of GEMs you want to ignore versions and comments
|
48
62
|
* `ignore_gem_versions`: Pass an array of GEMs you want to ignore versions
|
49
63
|
* `ignore_gem_comments`: Pass an array of GEMs you want to ignore comments
|
@@ -54,6 +68,7 @@ Example:
|
|
54
68
|
backup: true
|
55
69
|
update_comments: true
|
56
70
|
update_versions: false
|
71
|
+
use_double_quotes: true
|
57
72
|
ignore_gems:
|
58
73
|
- byebug
|
59
74
|
- discard
|
@@ -62,7 +77,8 @@ ignore_gem_versions:
|
|
62
77
|
ignore_gem_comments:
|
63
78
|
- otpor
|
64
79
|
```
|
65
|
-
This will sort your Gemfile, create a backup,
|
80
|
+
This will sort your Gemfile, create a backup, update comments, convert single quotes to double quotes, and ignore specific gems for different operations.
|
81
|
+
|
66
82
|
## Example
|
67
83
|
### Input Gemfile
|
68
84
|
```ruby
|
data/lib/gem_sorter/version.rb
CHANGED
data/lib/gem_sorter.rb
CHANGED
@@ -41,11 +41,49 @@ module GemSorter
|
|
41
41
|
result << ''
|
42
42
|
end
|
43
43
|
|
44
|
+
result = transform_to_double_quotes(result) if @config.use_double_quotes
|
45
|
+
|
44
46
|
result.join("\n")
|
45
47
|
end
|
46
48
|
|
47
49
|
private
|
48
50
|
|
51
|
+
def transform_to_double_quotes(gem_file_content)
|
52
|
+
return gem_file_content unless gem_file_content.is_a?(Array) || gem_file_content.is_a?(String)
|
53
|
+
|
54
|
+
content = gem_file_content.is_a?(Array) ? gem_file_content : gem_file_content.split("\n")
|
55
|
+
|
56
|
+
transformed_content = content.map do |line|
|
57
|
+
next line if line.nil? || line.strip.empty?
|
58
|
+
|
59
|
+
if line.strip.start_with?('#')
|
60
|
+
line
|
61
|
+
elsif line.include?('gem') && line =~ /gem\s+[']/
|
62
|
+
begin
|
63
|
+
parts = line.split('#', 2)
|
64
|
+
main_part = parts[0]
|
65
|
+
comment_part = parts[1]
|
66
|
+
processed_main = main_part.gsub(/gem\s+'([^']+)'/) { |m| %Q{gem "#{$1}"} }
|
67
|
+
|
68
|
+
if comment_part
|
69
|
+
"#{processed_main}##{comment_part}"
|
70
|
+
else
|
71
|
+
processed_main
|
72
|
+
end
|
73
|
+
rescue => e
|
74
|
+
puts "Error transforming to double quotes: #{e.message}"
|
75
|
+
line
|
76
|
+
end
|
77
|
+
elsif line.include?('source')
|
78
|
+
line.gsub("'", '"')
|
79
|
+
else
|
80
|
+
line
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
gem_file_content.is_a?(Array) ? transformed_content : transformed_content.join("\n")
|
85
|
+
end
|
86
|
+
|
49
87
|
def update_version_text(gems)
|
50
88
|
@versions ||= fetch_versions_from_lockfile("#{@filepath}.lock")
|
51
89
|
gems.each do |gem_block|
|
data/lib/task_config.rb
CHANGED
@@ -8,6 +8,7 @@ module GemSorter
|
|
8
8
|
'backup' => false,
|
9
9
|
'update_comments' => false,
|
10
10
|
'update_versions' => false,
|
11
|
+
'use_double_quotes' => false,
|
11
12
|
'gemfile_path' => 'Gemfile',
|
12
13
|
'ignore_gems' => [],
|
13
14
|
'ignore_gem_versions' => [],
|
@@ -18,6 +19,7 @@ module GemSorter
|
|
18
19
|
@backup = nil
|
19
20
|
@update_comments = nil
|
20
21
|
@update_versions = nil
|
22
|
+
@use_double_quotes = nil
|
21
23
|
@ignore_gems = nil
|
22
24
|
@ignore_gem_versions = nil
|
23
25
|
@ignore_gem_comments = nil
|
@@ -37,6 +39,10 @@ module GemSorter
|
|
37
39
|
@update_versions.nil? ? DEFAULT_CONFIG['update_versions'] : @update_versions
|
38
40
|
end
|
39
41
|
|
42
|
+
def use_double_quotes
|
43
|
+
@use_double_quotes.nil? ? DEFAULT_CONFIG['use_double_quotes'] : @use_double_quotes
|
44
|
+
end
|
45
|
+
|
40
46
|
def ignore_gems
|
41
47
|
@ignore_gems.nil? ? DEFAULT_CONFIG['ignore_gems'] : @ignore_gems
|
42
48
|
end
|
@@ -68,6 +74,7 @@ module GemSorter
|
|
68
74
|
@update_comments = task_config['update_comments'] if task_config.key?('update_comments')
|
69
75
|
@update_versions = task_config['update_versions'] if task_config.key?('update_versions')
|
70
76
|
@gemfile_path = task_config['gemfile_path'] if task_config.key?('gemfile_path')
|
77
|
+
@use_double_quotes = task_config['use_double_quotes'] if task_config.key?('use_double_quotes')
|
71
78
|
@ignore_gems = task_config['ignore_gems'] if task_config.key?('ignore_gems')
|
72
79
|
@ignore_gem_versions = task_config['ignore_gem_versions'] if task_config.key?('ignore_gem_versions')
|
73
80
|
@ignore_gem_comments = task_config['ignore_gem_comments'] if task_config.key?('ignore_gem_comments')
|
@@ -80,6 +87,7 @@ module GemSorter
|
|
80
87
|
@update_comments = parse_boolean(args[:update_comments]) unless args[:update_comments].nil?
|
81
88
|
@update_versions = parse_boolean(args[:update_versions]) unless args[:update_versions].nil?
|
82
89
|
@gemfile_path = args[:gemfile_path] unless args[:gemfile_path].nil?
|
90
|
+
@use_double_quotes = parse_boolean(args[:use_double_quotes]) unless args[:use_double_quotes].nil?
|
83
91
|
@ignore_gems = args[:ignore_gems] unless args[:ignore_gems].nil?
|
84
92
|
@ignore_gem_versions = args[:ignore_gem_versions] unless args[:ignore_gem_versions].nil?
|
85
93
|
@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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renan Garcia
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-24 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|