gem_sorter 0.5.0 → 0.5.2
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 +2 -0
- data/lib/gem_sorter/version.rb +1 -1
- data/lib/gem_sorter.rb +30 -7
- 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: 3a14433575929ce85e046a16391ef12ca535aaf889e270311831d6afc84d39c7
|
4
|
+
data.tar.gz: efffe4275cca1eb81d9f824e858945748070137c57d0c6872ec66b985aca7125
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc7cc1833d9c17b4b04e4a0442fa8e09630a48cce2eae2bf316726f4f267ce77e0d23e87b60783d776c1da7433ebb5ca06f0eaf72f8efb33c520628f74af27d
|
7
|
+
data.tar.gz: 3c5b1e7ae3724f8b3143daac366df453c9196a92b5123e6972a9ea2713d32a9f46a161625a5c817f9a074896a7d2c91a90cb78fb73b370db5e4ed8f43d47f496
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
<img src="https://i.imgur.com/WHOyL9W.png" width="150" alt="GemSorter Logo">
|
3
3
|
</p>
|
4
4
|
|
5
|
+
[](https://badge.fury.io/rb/gem_sorter)
|
6
|
+
|
5
7
|
# GemSorter
|
6
8
|
|
7
9
|
GemSorter is a simple gem to sort the contents of your Gemfile alphabetically while preserving comments and group structure. It helps maintain a clean and organized Gemfile.
|
data/lib/gem_sorter/version.rb
CHANGED
data/lib/gem_sorter.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# lib/gem_sorter.rb
|
2
2
|
require 'net/http'
|
3
3
|
require 'cgi'
|
4
|
+
require 'openssl'
|
4
5
|
|
5
6
|
load File.expand_path('tasks/gem_sorter.rake', __dir__) if defined?(Rake)
|
6
7
|
|
@@ -14,11 +15,13 @@ module GemSorter
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def sort
|
18
|
+
ruby_line = extract_ruby_line(@content)
|
19
|
+
|
17
20
|
parts = @content.split(/^group/)
|
18
21
|
main_section = parts.shift
|
19
22
|
group_sections = parts
|
20
23
|
|
21
|
-
source_line, gems = process_main_section(main_section)
|
24
|
+
source_line, gems, _ = process_main_section(main_section)
|
22
25
|
|
23
26
|
update_gem_summaries(gems) if @config.update_comments
|
24
27
|
update_version_text(gems) if @config.update_versions
|
@@ -27,6 +30,10 @@ module GemSorter
|
|
27
30
|
|
28
31
|
result = []
|
29
32
|
result << source_line
|
33
|
+
if ruby_line
|
34
|
+
result << ''
|
35
|
+
result << ruby_line
|
36
|
+
end
|
30
37
|
result << ''
|
31
38
|
result.concat(sorted_gems)
|
32
39
|
result << ''
|
@@ -49,6 +56,12 @@ module GemSorter
|
|
49
56
|
|
50
57
|
private
|
51
58
|
|
59
|
+
def extract_ruby_line(content)
|
60
|
+
lines = content.split("\n")
|
61
|
+
ruby_line = lines.find { |line| line.strip.start_with?('ruby') }
|
62
|
+
ruby_line&.strip
|
63
|
+
end
|
64
|
+
|
52
65
|
def transform_to_double_quotes(gem_file_content)
|
53
66
|
return gem_file_content unless gem_file_content.is_a?(Array) || gem_file_content.is_a?(String)
|
54
67
|
|
@@ -147,11 +160,14 @@ module GemSorter
|
|
147
160
|
source_line = lines.shift
|
148
161
|
|
149
162
|
gems = []
|
163
|
+
ruby_line = nil
|
150
164
|
current_comments = []
|
151
165
|
|
152
166
|
lines.each do |line|
|
153
167
|
if line.start_with?('#')
|
154
168
|
current_comments << line
|
169
|
+
elsif line.start_with?('ruby')
|
170
|
+
ruby_line = line
|
155
171
|
elsif line.start_with?('gem')
|
156
172
|
gems << {
|
157
173
|
comments: current_comments,
|
@@ -161,7 +177,7 @@ module GemSorter
|
|
161
177
|
end
|
162
178
|
end
|
163
179
|
|
164
|
-
[source_line, gems]
|
180
|
+
[source_line, gems, ruby_line]
|
165
181
|
end
|
166
182
|
|
167
183
|
def process_group_section(section)
|
@@ -215,7 +231,7 @@ module GemSorter
|
|
215
231
|
return get_summary(gem_name, true) unless remote
|
216
232
|
nil
|
217
233
|
end
|
218
|
-
rescue StandardError
|
234
|
+
rescue StandardError
|
219
235
|
nil
|
220
236
|
end
|
221
237
|
|
@@ -224,11 +240,18 @@ module GemSorter
|
|
224
240
|
url = URI(version ? "#{base_url}/versions/#{version.strip}" : base_url)
|
225
241
|
|
226
242
|
begin
|
227
|
-
|
228
|
-
|
229
|
-
|
243
|
+
http = Net::HTTP.new(url.host, url.port)
|
244
|
+
http.use_ssl = true
|
245
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
246
|
+
|
247
|
+
request = Net::HTTP::Get.new(url)
|
248
|
+
response = http.request(request)
|
249
|
+
|
250
|
+
unless response.is_a?(Net::HTTPSuccess)
|
251
|
+
raise "Error: Could not fetch gem information from RubyGems for #{gem_name} version #{version}. Status: #{response.code}"
|
230
252
|
end
|
231
|
-
|
253
|
+
|
254
|
+
match = response.body.match(/<input[^>]*id=["']gemfile_text["'][^>]*value=["']([^"']+)["']/)
|
232
255
|
|
233
256
|
if match
|
234
257
|
CGI.unescapeHTML(match[1])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_sorter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renan Garcia
|
@@ -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.8
|
74
74
|
specification_version: 4
|
75
75
|
summary: Sort gems in the Gemfile alphabetically
|
76
76
|
test_files: []
|