alphabetize 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/Rakefile +92 -0
- data/alphabetize.gemspec +25 -2
- data/lib/alphabetize.rb +117 -10
- data/test/helper.rb +11 -0
- data/test/sample_Gemfiles/mixed_Gemfile +46 -0
- data/test/sample_Gemfiles/out_regular_chunks_Gemfile +0 -0
- data/test/sample_Gemfiles/out_static_chunks_Gemfile +0 -0
- data/test/sample_Gemfiles/regular_chunks_Gemfile +0 -0
- data/test/sample_Gemfiles/simple_Gemfile +21 -0
- data/test/sample_Gemfiles/static_chunks_Gemfile +0 -0
- data/test/test_alphabetize.rb +4 -0
- metadata +20 -5
- data/.gitignore +0 -17
- data/lib/alphabetize/version.rb +0 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Alphabetize
|
2
2
|
|
3
|
-
|
3
|
+
Ruby gem to soothe your OCDs by alphabetizing your Gemfile
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,9 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Go to root level of your rails app and run
|
22
|
+
|
23
|
+
$ alphabetize
|
22
24
|
|
23
25
|
## Contributing
|
24
26
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,94 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
# Most of these rake tasks were obtained from jekyll's Rakefile: #src TODO
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[lib]))
|
7
|
+
|
8
|
+
#############################################################################
|
9
|
+
#
|
10
|
+
# Helper functions
|
11
|
+
#
|
12
|
+
#############################################################################
|
13
|
+
|
14
|
+
def name
|
15
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
16
|
+
end
|
17
|
+
|
18
|
+
def version
|
19
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
20
|
+
puts "Line read: #{line}"
|
21
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def date
|
25
|
+
Date.today.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def rubyforge_project
|
29
|
+
name
|
30
|
+
end
|
31
|
+
|
32
|
+
def gemspec_file
|
33
|
+
"#{name}.gemspec"
|
34
|
+
end
|
35
|
+
|
36
|
+
def gem_file
|
37
|
+
"#{name}-#{version}.gem"
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_header(head, header_name)
|
41
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
42
|
+
end
|
43
|
+
|
44
|
+
#############################################################################
|
45
|
+
#
|
46
|
+
# Packaging tasks
|
47
|
+
#
|
48
|
+
#############################################################################
|
49
|
+
|
50
|
+
task :release => :build do
|
51
|
+
unless `git branch` =~ /^\* master$/
|
52
|
+
puts "You must be on the master branch to release!"
|
53
|
+
exit!
|
54
|
+
end
|
55
|
+
sh "git commit --allow-empty -m 'Release #{version}'"
|
56
|
+
sh "git tag v#{version}"
|
57
|
+
sh "git push origin master"
|
58
|
+
sh "git push origin v#{version}"
|
59
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
60
|
+
end
|
61
|
+
|
62
|
+
task :build => :gemspec do
|
63
|
+
sh "mkdir -p pkg"
|
64
|
+
sh "gem build #{gemspec_file}"
|
65
|
+
sh "mv #{gem_file} pkg"
|
66
|
+
end
|
67
|
+
|
68
|
+
task :gemspec do
|
69
|
+
# read spec file and split out manifest section
|
70
|
+
spec = File.read(gemspec_file)
|
71
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
72
|
+
|
73
|
+
# replace name version and date
|
74
|
+
replace_header(head, :name)
|
75
|
+
replace_header(head, :version)
|
76
|
+
replace_header(head, :date)
|
77
|
+
#comment this out if your rubyforge_project has a different name
|
78
|
+
replace_header(head, :rubyforge_project)
|
79
|
+
|
80
|
+
# determine file list from git ls-files
|
81
|
+
files = `git ls-files`.
|
82
|
+
split("\n").
|
83
|
+
sort.
|
84
|
+
reject { |file| file =~ /^\./ }.
|
85
|
+
reject { |file| file =~ /^(rdoc|pkg|coverage)/ }.
|
86
|
+
map { |file| " #{file}" }.
|
87
|
+
join("\n")
|
88
|
+
|
89
|
+
# piece file back together and write
|
90
|
+
manifest = " gem.files = %w[\n#{files}\n ]\n"
|
91
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
92
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
93
|
+
puts "Updated #{gemspec_file}"
|
94
|
+
end
|
data/alphabetize.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'lib/alphabetize'
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
5
7
|
gem.authors = ["Vidur Murali"]
|
@@ -14,4 +16,25 @@ Gem::Specification.new do |gem|
|
|
14
16
|
gem.name = "alphabetize"
|
15
17
|
gem.require_paths = ["lib"]
|
16
18
|
gem.version = Alphabetize::VERSION
|
17
|
-
|
19
|
+
|
20
|
+
# = MANIFEST =
|
21
|
+
gem.files = %w[
|
22
|
+
Gemfile
|
23
|
+
LICENSE
|
24
|
+
README.md
|
25
|
+
Rakefile
|
26
|
+
alphabetize.gemspec
|
27
|
+
bin/alphabetize
|
28
|
+
lib/alphabetize.rb
|
29
|
+
test/helper.rb
|
30
|
+
test/sample_Gemfiles/mixed_Gemfile
|
31
|
+
test/sample_Gemfiles/out_regular_chunks_Gemfile
|
32
|
+
test/sample_Gemfiles/out_static_chunks_Gemfile
|
33
|
+
test/sample_Gemfiles/regular_chunks_Gemfile
|
34
|
+
test/sample_Gemfiles/simple_Gemfile
|
35
|
+
test/sample_Gemfiles/static_chunks_Gemfile
|
36
|
+
test/test_alphabetize.rb
|
37
|
+
]
|
38
|
+
# = MANIFEST =
|
39
|
+
|
40
|
+
end
|
data/lib/alphabetize.rb
CHANGED
@@ -1,37 +1,144 @@
|
|
1
|
-
|
1
|
+
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
|
2
|
+
|
3
|
+
# The Gemfile is parsed into file_chunks array
|
4
|
+
# Each chunk has the following attributes:
|
5
|
+
# :type - :static (don't sort them), :regular, :group (official group, use the header, end correctly)
|
6
|
+
# :header - the line that prepends the chunk
|
7
|
+
# :gem_hash - the hash of gems that belong to this chunk
|
8
|
+
#
|
2
9
|
|
3
10
|
module Alphabetize
|
4
|
-
|
11
|
+
VERSION = "0.1.0"
|
12
|
+
|
13
|
+
def self.alphabetize_file
|
14
|
+
filename = "Gemfile"
|
5
15
|
file = File.new(filename)
|
6
16
|
|
7
17
|
lines = file.readlines
|
8
|
-
|
18
|
+
puts "File Lines: #{lines.inspect}"
|
19
|
+
file_chunks = make_chunky(lines)
|
20
|
+
|
21
|
+
puts "Chunks: #{file_chunks.inspect}"
|
9
22
|
|
10
23
|
backupFilename = "old_#{filename}"
|
11
24
|
%x( mv #{filename} #{backupFilename})
|
12
25
|
|
13
26
|
file = File.open(filename, 'w')
|
14
|
-
file.truncate(0) # clear the file
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
# file.truncate(0) # clear the file
|
28
|
+
|
29
|
+
file_chunks.each do |chunk|
|
30
|
+
if chunk[:type] == :static
|
31
|
+
print_gem_hash(file, chunk[:gem_hash])
|
32
|
+
elsif chunk[:type] == :group
|
33
|
+
file.puts(chunk[:header])
|
34
|
+
print_gem_hash(file, chunk[:gem_hash])
|
35
|
+
file.puts("end")
|
36
|
+
elsif chunk[:type] == :regular
|
37
|
+
print_gem_hash(file, chunk[:gem_hash])
|
38
|
+
else
|
39
|
+
raise "This chunk has some wierd type!"
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# chunk.keys.sort.each do |gem|
|
44
|
+
# line = chunk[gem]
|
45
|
+
# file.puts(line)
|
46
|
+
# end
|
47
|
+
file.puts("")
|
18
48
|
end
|
49
|
+
|
19
50
|
file.close
|
20
51
|
|
21
52
|
end
|
22
53
|
|
23
|
-
|
24
|
-
|
54
|
+
private
|
55
|
+
def self.make_chunky(lines)
|
56
|
+
chunks = []
|
25
57
|
|
58
|
+
chunk = {}
|
59
|
+
chunk_gem_lines = []
|
26
60
|
lines.each do |line|
|
61
|
+
puts "* Processing line: #{line}"
|
62
|
+
if line != "\n"
|
63
|
+
if line.match(/##/) # static chunk
|
64
|
+
chunk[:type] = :static
|
65
|
+
puts "Thinks its static"
|
66
|
+
chunk[:gem_hash] = gem_hash([line])
|
67
|
+
chunks << chunk
|
68
|
+
chunk = {}
|
69
|
+
chunk_gem_lines = []
|
70
|
+
|
71
|
+
elsif line.match(/do/) # official start of a group
|
72
|
+
chunk[:type] = :group
|
73
|
+
chunk[:header] = line
|
74
|
+
|
75
|
+
elsif line.match(/^end/) # official end of a group
|
76
|
+
puts "Thinks its a group"
|
77
|
+
chunk[:gem_hash] = gem_hash(chunk_gem_lines)
|
78
|
+
chunks << chunk
|
79
|
+
chunk = {}
|
80
|
+
chunk_gem_lines = []
|
81
|
+
|
82
|
+
else # regular gem line
|
83
|
+
chunk[:type] = :regular if chunk == {} # start of a regualr chunk
|
84
|
+
chunk_gem_lines << line
|
85
|
+
end
|
86
|
+
|
87
|
+
elsif line == "\n" and chunk != {} # this is the end of some regular chunk
|
88
|
+
puts "Thinks its regular"
|
89
|
+
chunk[:gem_hash] = gem_hash(chunk_gem_lines)
|
90
|
+
chunks << chunk
|
91
|
+
chunk = {}
|
92
|
+
chunk_gem_lines = []
|
93
|
+
|
94
|
+
else # two new line characters in a row
|
95
|
+
puts "**** Skipping line: #{line}"
|
96
|
+
# do nothing
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# if line contains '##'
|
101
|
+
# mark chunk as :static
|
102
|
+
# if line contains 'do'
|
103
|
+
# mark chunk as :group
|
104
|
+
#
|
105
|
+
# if line == "\n" and !chunk_gem_lines.empty?
|
106
|
+
# chunk[:gem_hash] = gem_hash(chunk_gem_lines)
|
107
|
+
# chunks << chunk
|
108
|
+
# chunk_gem_lines = [] # reset chunk lines
|
109
|
+
# else
|
110
|
+
# chunk_gem_lines << line if line != "\n"
|
111
|
+
# end
|
112
|
+
end
|
113
|
+
|
114
|
+
if chunk != {}
|
115
|
+
chunk[:gem_hash] = gem_hash(chunk_gem_lines)
|
116
|
+
chunks << chunk
|
117
|
+
end
|
118
|
+
|
119
|
+
chunks
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.gem_hash(lines)
|
123
|
+
hash = {}
|
124
|
+
puts "-------- Inspecting lines: #{lines.inspect}"
|
125
|
+
lines.each do |line|
|
126
|
+
puts "Line: #{line}"
|
27
127
|
match_data = line.scan(/(\"([^"]*)\")|(\'([^']*)\')/)
|
28
128
|
# The gem is either the second element or the 4th element of the array
|
29
129
|
gem ||= match_data[0][1]
|
30
130
|
gem ||= match_data[0].last
|
31
|
-
|
131
|
+
puts "Found gem: #{gem}"
|
32
132
|
hash[gem] = line
|
33
133
|
end
|
34
134
|
|
35
135
|
hash
|
36
136
|
end
|
137
|
+
|
138
|
+
def self.print_gem_hash(out, hash)
|
139
|
+
hash.keys.sort.each do |gem|
|
140
|
+
line = hash[gem]
|
141
|
+
out.puts(line)
|
142
|
+
end
|
143
|
+
end
|
37
144
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
gem 'rails', '3.1.3'
|
2
|
+
gem 'pg'
|
3
|
+
gem 'jquery-rails'
|
4
|
+
gem "zurbfoundation"
|
5
|
+
gem 'devise'
|
6
|
+
gem 'icalendar'
|
7
|
+
gem 'omniauth-facebook'
|
8
|
+
gem 'cancan'
|
9
|
+
gem 'nested_form', :git => 'https://github.com/jweslley/nested_form.git'
|
10
|
+
gem 'datejsrails'
|
11
|
+
|
12
|
+
group :assets do
|
13
|
+
gem 'sass-rails', '~> 3.1.5'
|
14
|
+
gem 'coffee-rails', '~> 3.1.1'
|
15
|
+
gem 'uglifier', '>= 1.0.3'
|
16
|
+
end
|
17
|
+
|
18
|
+
group :development do
|
19
|
+
gem 'kumade', '~> 0.8.1'
|
20
|
+
gem 'letter_opener'
|
21
|
+
gem 'ruby-debug19', :platforms => :ruby_19#, :require => 'ruby-debug'
|
22
|
+
end
|
23
|
+
|
24
|
+
group :development, :test do
|
25
|
+
gem 'factory_girl_rails'
|
26
|
+
gem 'rspec-rails', '~> 2.7'
|
27
|
+
gem 'shoulda-matchers'
|
28
|
+
gem 'email_spec'
|
29
|
+
gem 'guard-livereload'
|
30
|
+
gem 'yajl-ruby' # speed up LiveReload JSON
|
31
|
+
gem 'rb-notifu', :platforms => :mingw
|
32
|
+
gem 'rb-fchange', :platforms => :mingw
|
33
|
+
gem 'eventmachine', '>= 1.0.0.beta.4', :platforms => :mingw
|
34
|
+
end
|
35
|
+
|
36
|
+
group :test do
|
37
|
+
gem "capybara", '~> 1.1.2' # for spec/requests
|
38
|
+
gem 'launchy' # for save_and_open_page
|
39
|
+
gem 'spork'
|
40
|
+
gem 'guard-spork'
|
41
|
+
gem 'rb-fsevent'
|
42
|
+
gem 'guard-rspec'
|
43
|
+
gem 'simplecov', '~> 0.5.4'
|
44
|
+
gem 'shoulda', '~> 2.11.3'
|
45
|
+
gem 'factory_girl_rails'
|
46
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
gem 'fixed-gem', '3.2.1' ## Don't want this to move from line 1
|
2
|
+
gem 'bcrypt-ruby', '3.0.1'
|
3
|
+
gem 'jquery-rails', '2.0.2'
|
4
|
+
|
5
|
+
gem 'fixed-gem', '3.2.1' ## Don't want this to move from line 5
|
6
|
+
gem 'pg', '0.13.2'
|
7
|
+
gem 'uglifier', '1.0.3'
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'private_pub'
|
11
|
+
gem 'sass-rails', '3.2.3'
|
12
|
+
gem 'rails', '3.2.3'
|
13
|
+
gem 'js-routes'
|
14
|
+
gem 'rails-erd'
|
15
|
+
gem 'growl'
|
16
|
+
end
|
17
|
+
|
18
|
+
gem 'shoulda-matchers'
|
19
|
+
gem 'spork'
|
20
|
+
gem 'faker'
|
21
|
+
gem 'simplecov', :require => false
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphabetize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-02 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Alphabetizes your gemfile
|
15
15
|
email:
|
@@ -19,7 +19,6 @@ executables:
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
-
- .gitignore
|
23
22
|
- Gemfile
|
24
23
|
- LICENSE
|
25
24
|
- README.md
|
@@ -27,7 +26,14 @@ files:
|
|
27
26
|
- alphabetize.gemspec
|
28
27
|
- bin/alphabetize
|
29
28
|
- lib/alphabetize.rb
|
30
|
-
-
|
29
|
+
- test/helper.rb
|
30
|
+
- test/sample_Gemfiles/mixed_Gemfile
|
31
|
+
- test/sample_Gemfiles/out_regular_chunks_Gemfile
|
32
|
+
- test/sample_Gemfiles/out_static_chunks_Gemfile
|
33
|
+
- test/sample_Gemfiles/regular_chunks_Gemfile
|
34
|
+
- test/sample_Gemfiles/simple_Gemfile
|
35
|
+
- test/sample_Gemfiles/static_chunks_Gemfile
|
36
|
+
- test/test_alphabetize.rb
|
31
37
|
homepage: https://github.com/vyder/alphabetize
|
32
38
|
licenses: []
|
33
39
|
post_install_message:
|
@@ -53,4 +59,13 @@ signing_key:
|
|
53
59
|
specification_version: 3
|
54
60
|
summary: Please check how far I've got with the file parsing before you use this gem.
|
55
61
|
It does create a backup of your gemfile in case things go seriously wrong.'
|
56
|
-
test_files:
|
62
|
+
test_files:
|
63
|
+
- test/helper.rb
|
64
|
+
- test/sample_Gemfiles/mixed_Gemfile
|
65
|
+
- test/sample_Gemfiles/out_regular_chunks_Gemfile
|
66
|
+
- test/sample_Gemfiles/out_static_chunks_Gemfile
|
67
|
+
- test/sample_Gemfiles/regular_chunks_Gemfile
|
68
|
+
- test/sample_Gemfiles/simple_Gemfile
|
69
|
+
- test/sample_Gemfiles/static_chunks_Gemfile
|
70
|
+
- test/test_alphabetize.rb
|
71
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/lib/alphabetize/version.rb
DELETED