gem_sort 0.1.0 → 0.2.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/lib/gem_sort/sorter.rb +9 -1
- data/lib/gem_sort/version.rb +1 -1
- data/test/dummy/config/application.rb +11 -15
- data/test/test_helper.rb +0 -2
- metadata +4 -21
- data/lib/gem_sort/sorter.rb~ +0 -108
- data/lib/gem_sort/version.rb~ +0 -3
- data/lib/tasks/gem_sort_tasks.rake~ +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63039423becb32baf6af0079b3115773ca1f4470
|
4
|
+
data.tar.gz: fccd096f8892c4dc81bb7ac9d95d43e215068a4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7af44040ab3643dc6211bec7a2ddeeb67e578b8b4ec40b9e79e82d40fe2c65c7b2c9abbe3c75117d4adda5dafa42671a8a22564d85d74a66481f887456bd787c
|
7
|
+
data.tar.gz: 754d0c308019d4920c723d2b27a78a5fcc34397819e1b9940e7f8ea1f6cd9e13f7271125a6644fa22883aaa20396e642b1f07d5a38fa3baf24888ee93e182a5c
|
data/lib/gem_sort/sorter.rb
CHANGED
@@ -55,8 +55,16 @@ module GemSort
|
|
55
55
|
source_gemfile.read.split("\n").select{ |line| line != "" }
|
56
56
|
end
|
57
57
|
|
58
|
+
def removal_comment_and_blank(text)
|
59
|
+
text.gsub(/#.*$/,'').gsub(/\n(\s| )*\n/, "\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
def magic_comment
|
63
|
+
"# frozen_string_literal: true\n"
|
64
|
+
end
|
65
|
+
|
58
66
|
def write_gemfile(text)
|
59
|
-
source_gemfile.write(text)
|
67
|
+
source_gemfile.write(magic_comment + removal_comment_and_blank(text))
|
60
68
|
end
|
61
69
|
|
62
70
|
def sort!
|
data/lib/gem_sort/version.rb
CHANGED
@@ -1,26 +1,22 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
require 'rails
|
3
|
+
require 'rails'
|
4
|
+
# Pick the frameworks you want:
|
5
|
+
require 'active_model/railtie'
|
6
|
+
# require 'active_record/railtie'
|
7
|
+
require 'action_controller/railtie'
|
8
|
+
require 'action_mailer/railtie'
|
9
|
+
require 'action_view/railtie'
|
10
|
+
require 'sprockets/railtie'
|
11
|
+
require 'rails/test_unit/railtie'
|
12
|
+
|
13
|
+
|
4
14
|
|
5
15
|
Bundler.require(*Rails.groups)
|
6
16
|
require "gem_sort"
|
7
17
|
|
8
18
|
module Dummy
|
9
19
|
class Application < Rails::Application
|
10
|
-
# Settings in config/environments/* take precedence over those specified here.
|
11
|
-
# Application configuration should go into files in config/initializers
|
12
|
-
# -- all .rb files in that directory are automatically loaded.
|
13
|
-
|
14
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
-
|
18
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
-
# config.i18n.default_locale = :de
|
21
|
-
|
22
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
-
config.active_record.raise_in_transactional_callbacks = true
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
data/test/test_helper.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
ENV["RAILS_ENV"] = "test"
|
3
3
|
|
4
4
|
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
5
|
-
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
6
|
-
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
|
7
5
|
require "rails/test_help"
|
8
6
|
|
9
7
|
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
metadata
CHANGED
@@ -1,37 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.2'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '4.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: sqlite3
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '0'
|
34
|
-
type: :
|
20
|
+
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
@@ -57,11 +43,8 @@ files:
|
|
57
43
|
- lib/gem_sort.rb
|
58
44
|
- lib/gem_sort/engine.rb
|
59
45
|
- lib/gem_sort/sorter.rb
|
60
|
-
- lib/gem_sort/sorter.rb~
|
61
46
|
- lib/gem_sort/version.rb
|
62
|
-
- lib/gem_sort/version.rb~
|
63
47
|
- lib/tasks/gem_sort_tasks.rake
|
64
|
-
- lib/tasks/gem_sort_tasks.rake~
|
65
48
|
- test/dummy/README.rdoc
|
66
49
|
- test/dummy/Rakefile
|
67
50
|
- test/dummy/app/assets/javascripts/application.js
|
@@ -119,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
102
|
version: '0'
|
120
103
|
requirements: []
|
121
104
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.5.1
|
123
106
|
signing_key:
|
124
107
|
specification_version: 4
|
125
108
|
summary: Sorting your gems in Gemfile (for Rails)
|
data/lib/gem_sort/sorter.rb~
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
module GemSort
|
2
|
-
class Sorter
|
3
|
-
def extract_blocks!(lines, begin_block_condition, nested = false)
|
4
|
-
end_block_condition = -> (line) {
|
5
|
-
(nested ? line.strip : line).start_with?("end")
|
6
|
-
}
|
7
|
-
blocks = []
|
8
|
-
|
9
|
-
while lines.select(&begin_block_condition).length > 0
|
10
|
-
begin_block_index = lines.index(&begin_block_condition)
|
11
|
-
block_length = lines
|
12
|
-
.slice(begin_block_index..lines.length)
|
13
|
-
.index(&end_block_condition)
|
14
|
-
block_length += 1
|
15
|
-
blocks << lines.slice!(begin_block_index, block_length)
|
16
|
-
end
|
17
|
-
blocks
|
18
|
-
end
|
19
|
-
|
20
|
-
def extract_line!(lines, condition)
|
21
|
-
target_line = lines.select(&condition).first
|
22
|
-
lines.delete_if{ |line| line == target_line } if target_line != nil
|
23
|
-
target_line
|
24
|
-
end
|
25
|
-
|
26
|
-
def sort_block_gems(block)
|
27
|
-
wrap_block(block, unwrap_block(block).sort)
|
28
|
-
end
|
29
|
-
|
30
|
-
def wrap_block(block, inside)
|
31
|
-
[
|
32
|
-
block.first,
|
33
|
-
*inside,
|
34
|
-
block.last
|
35
|
-
]
|
36
|
-
end
|
37
|
-
|
38
|
-
def unwrap_block(block)
|
39
|
-
block[1..block.length - 2]
|
40
|
-
end
|
41
|
-
|
42
|
-
def inject_between(array, divider)
|
43
|
-
array.each_with_index.inject([]) { |acc, (item, i)|
|
44
|
-
acc << item
|
45
|
-
acc << divider if array.last != item
|
46
|
-
acc
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
def source_gemfile
|
51
|
-
::Rails.root.join('Gemfile').open('r+')
|
52
|
-
end
|
53
|
-
|
54
|
-
def read_gemfile
|
55
|
-
source_gemfile.read.split("\n").select{ |line| line != "" }
|
56
|
-
end
|
57
|
-
|
58
|
-
def write_gemfile(text)
|
59
|
-
source_gemfile.write(text)
|
60
|
-
end
|
61
|
-
|
62
|
-
def sort!
|
63
|
-
gemfile = read_gemfile
|
64
|
-
|
65
|
-
group_blocks = extract_blocks!(gemfile, -> (line) {
|
66
|
-
line.start_with?("group")
|
67
|
-
}).map{ |group_block|
|
68
|
-
sort_block_gems(group_block)
|
69
|
-
}
|
70
|
-
|
71
|
-
source_blocks = extract_blocks!(gemfile, -> (line) {
|
72
|
-
line.start_with?("source ") && line.end_with?("do")
|
73
|
-
}).map{ |source_block|
|
74
|
-
source_inside = unwrap_block(source_block)
|
75
|
-
inside_group_blocks = extract_blocks!(source_inside, -> (line) {
|
76
|
-
line.strip.start_with?("group")
|
77
|
-
}, true).map{ |inside_group_block|
|
78
|
-
sort_block_gems(inside_group_block)
|
79
|
-
}
|
80
|
-
inside = source_inside.sort + inject_between(inside_group_blocks, nil)
|
81
|
-
wrap_block(source_block, inside)
|
82
|
-
}
|
83
|
-
|
84
|
-
source_line = extract_line!(gemfile, -> (line) {
|
85
|
-
line.start_with?('source') && !line.end_with?('do')
|
86
|
-
})
|
87
|
-
|
88
|
-
ruby_line = extract_line!(gemfile, -> (line) {
|
89
|
-
line.start_with?('ruby')
|
90
|
-
})
|
91
|
-
|
92
|
-
rails_line = extract_line!(gemfile, -> (line) {
|
93
|
-
line.start_with?('gem "rails"') || line.start_with?("gem 'rails'")
|
94
|
-
})
|
95
|
-
|
96
|
-
sorted_text = inject_between([
|
97
|
-
source_line,
|
98
|
-
[ruby_line, rails_line],
|
99
|
-
gemfile.sort,
|
100
|
-
inject_between(group_blocks, nil),
|
101
|
-
inject_between(source_blocks, nil)
|
102
|
-
], nil).flatten.join("\n")
|
103
|
-
|
104
|
-
write_gemfile(sorted_text)
|
105
|
-
=end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/lib/gem_sort/version.rb~
DELETED