gem_sort 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63039423becb32baf6af0079b3115773ca1f4470
4
- data.tar.gz: fccd096f8892c4dc81bb7ac9d95d43e215068a4a
3
+ metadata.gz: f6e056719ee27a7930aea72edcd0fb31830edec6
4
+ data.tar.gz: f36458cbfefa5acc31d5f7e611730e87d3a7d915
5
5
  SHA512:
6
- metadata.gz: 7af44040ab3643dc6211bec7a2ddeeb67e578b8b4ec40b9e79e82d40fe2c65c7b2c9abbe3c75117d4adda5dafa42671a8a22564d85d74a66481f887456bd787c
7
- data.tar.gz: 754d0c308019d4920c723d2b27a78a5fcc34397819e1b9940e7f8ea1f6cd9e13f7271125a6644fa22883aaa20396e642b1f07d5a38fa3baf24888ee93e182a5c
6
+ metadata.gz: c1d63351049cfe749bf14040a985ca79ec11a1e086f011ffe4d207fd40fd147b2f15ec48ab0493c622afa62ee075fd8382ff0faf63e6252490106d60050021f4
7
+ data.tar.gz: f2e3389731a5c5cbd6003e431b021053aec26faf3cbfc48fef7c9313daaf2dda48ec5bfdfdd04aaa383adf51449dddbb610bd783cbed4431784219d8c2640223
@@ -24,7 +24,7 @@ module GemSort
24
24
  end
25
25
 
26
26
  def sort_block_gems(block)
27
- wrap_block(block, unwrap_block(block).sort)
27
+ wrap_block(block, sort_gems(unwrap_block(block)))
28
28
  end
29
29
 
30
30
  def wrap_block(block, inside)
@@ -47,16 +47,24 @@ module GemSort
47
47
  }
48
48
  end
49
49
 
50
+ def sort_gems(gems)
51
+ gems.each { |line| line.gsub!(/\"/,"'") }.sort
52
+ end
53
+
50
54
  def source_gemfile
51
55
  ::Rails.root.join('Gemfile').open('r+')
52
56
  end
53
57
 
58
+ def initialized_gemfile
59
+ ::Rails.root.join('Gemfile').open('w')
60
+ end
61
+
54
62
  def read_gemfile
55
63
  source_gemfile.read.split("\n").select{ |line| line != "" }
56
64
  end
57
65
 
58
66
  def removal_comment_and_blank(text)
59
- text.gsub(/#.*$/,'').gsub(/\n(\s| )*\n/, "\n")
67
+ text.gsub(/#[^{].*$/,'').gsub(/\n(\s| )*\n/, "\n\n").gsub(/( | )+/, ' ')
60
68
  end
61
69
 
62
70
  def magic_comment
@@ -64,9 +72,10 @@ module GemSort
64
72
  end
65
73
 
66
74
  def write_gemfile(text)
67
- source_gemfile.write(magic_comment + removal_comment_and_blank(text))
75
+ initialized_gemfile.write(magic_comment + removal_comment_and_blank(text))
68
76
  end
69
77
 
78
+
70
79
  def sort!
71
80
  gemfile = read_gemfile
72
81
 
@@ -89,6 +98,16 @@ module GemSort
89
98
  wrap_block(source_block, inside)
90
99
  }
91
100
 
101
+ git_source_blocks = extract_line!(gemfile, -> (line) {
102
+ line.start_with?('git_source') && !line.include?('do')
103
+ })
104
+
105
+ git_source_blocks = extract_blocks!(gemfile, -> (line) {
106
+ line.start_with?("git_source")
107
+ }).map{ |group_block|
108
+ sort_block_gems(group_block)
109
+ } if git_source_blocks.nil?
110
+
92
111
  source_line = extract_line!(gemfile, -> (line) {
93
112
  line.start_with?('source') && !line.end_with?('do')
94
113
  })
@@ -102,9 +121,9 @@ module GemSort
102
121
  })
103
122
 
104
123
  sorted_text = inject_between([
105
- source_line,
124
+ [source_line, git_source_blocks],
106
125
  [ruby_line, rails_line],
107
- gemfile.sort,
126
+ sort_gems(gemfile),
108
127
  inject_between(group_blocks, nil),
109
128
  inject_between(source_blocks, nil)
110
129
  ], nil).flatten.join("\n")
@@ -1,3 +1,3 @@
1
1
  module GemSort
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kozo yamagata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -102,45 +102,45 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.5.1
105
+ rubygems_version: 2.5.2.3
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Sorting your gems in Gemfile (for Rails)
109
109
  test_files:
110
+ - test/dummy/app/controllers/application_controller.rb
111
+ - test/dummy/app/views/layouts/application.html.erb
110
112
  - test/dummy/app/assets/javascripts/application.js
111
113
  - test/dummy/app/assets/stylesheets/application.css
112
- - test/dummy/app/controllers/application_controller.rb
113
114
  - test/dummy/app/helpers/application_helper.rb
114
- - test/dummy/app/views/layouts/application.html.erb
115
- - test/dummy/bin/bundle
116
- - test/dummy/bin/rails
117
115
  - test/dummy/bin/rake
118
116
  - test/dummy/bin/setup
119
- - test/dummy/config/application.rb
120
- - test/dummy/config/boot.rb
121
- - test/dummy/config/database.yml
122
- - test/dummy/config/environment.rb
123
- - test/dummy/config/environments/development.rb
117
+ - test/dummy/bin/bundle
118
+ - test/dummy/bin/rails
119
+ - test/dummy/config/secrets.yml
120
+ - test/dummy/config/routes.rb
121
+ - test/dummy/config/locales/en.yml
124
122
  - test/dummy/config/environments/production.rb
123
+ - test/dummy/config/environments/development.rb
125
124
  - test/dummy/config/environments/test.rb
126
- - test/dummy/config/initializers/assets.rb
125
+ - test/dummy/config/environment.rb
126
+ - test/dummy/config/application.rb
127
+ - test/dummy/config/database.yml
128
+ - test/dummy/config/boot.rb
127
129
  - test/dummy/config/initializers/backtrace_silencers.rb
128
- - test/dummy/config/initializers/cookies_serializer.rb
129
- - test/dummy/config/initializers/filter_parameter_logging.rb
130
- - test/dummy/config/initializers/inflections.rb
131
130
  - test/dummy/config/initializers/mime_types.rb
131
+ - test/dummy/config/initializers/filter_parameter_logging.rb
132
132
  - test/dummy/config/initializers/session_store.rb
133
133
  - test/dummy/config/initializers/wrap_parameters.rb
134
- - test/dummy/config/locales/en.yml
135
- - test/dummy/config/routes.rb
136
- - test/dummy/config/secrets.yml
134
+ - test/dummy/config/initializers/assets.rb
135
+ - test/dummy/config/initializers/cookies_serializer.rb
136
+ - test/dummy/config/initializers/inflections.rb
137
137
  - test/dummy/config.ru
138
- - test/dummy/public/404.html
138
+ - test/dummy/Rakefile
139
+ - test/dummy/public/favicon.ico
139
140
  - test/dummy/public/422.html
140
141
  - test/dummy/public/500.html
141
- - test/dummy/public/favicon.ico
142
- - test/dummy/Rakefile
142
+ - test/dummy/public/404.html
143
143
  - test/dummy/README.rdoc
144
- - test/gem_sort_test.rb
145
144
  - test/integration/navigation_test.rb
145
+ - test/gem_sort_test.rb
146
146
  - test/test_helper.rb