alfalfa 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alfalfa.rb +9 -65
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c04046d3454853b7f27cf2a8d3337b7692fa61cc
|
4
|
+
data.tar.gz: 78b3f5671daa421912e8be4ab1cd5f265092e3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d53303735778df619626f381fb649dad46e8e58d2624c3044d6b1f6229d410276a0f2e2488321b57800d186ed94c6705b4cc48d97ffc6c560a005bcb9186d5ee
|
7
|
+
data.tar.gz: a3250779a08e83ff224d0659514b5462d9a91087622cca0923695fec951871e36b29a09ca97868892418bbbb0271f96433cf551a864b95ede9112e069ed921a6
|
data/lib/alfalfa.rb
CHANGED
@@ -1,81 +1,25 @@
|
|
1
|
-
|
1
|
+
require_relative "alfalfa/sort/gem.rb"
|
2
|
+
|
3
|
+
class Alfalfa
|
4
|
+
|
2
5
|
PWD_ARR = Dir.entries(Dir.pwd)
|
3
6
|
|
4
|
-
|
7
|
+
|
5
8
|
def self.is_gemfile?
|
9
|
+
# User may call this to see if the Gemfile is visible.
|
6
10
|
puts Alfalfa::PWD_ARR.include?("Gemfile")
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.sort_gemfile
|
14
|
+
# If the current directory has a Gemfile, set its contents to file and call partition.
|
10
15
|
if Alfalfa::PWD_ARR.include?("Gemfile")
|
11
16
|
file = File.read("Gemfile")
|
12
17
|
File.open("Gemfile")
|
13
|
-
partition_file(file)
|
18
|
+
Alfalfa::Gem.partition_file(file)
|
14
19
|
else
|
15
20
|
puts "No Gemfile found!"
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
sg = segment_groups(file)
|
21
|
-
sng = segment_non_groups(file)
|
22
|
-
ss = segment_source(file)
|
23
|
-
rewrite_gemfile(sg,sng,ss)
|
24
|
-
end
|
25
|
-
|
26
|
-
def rewrite_gemfile(sg,sng,ss)
|
27
|
-
File.open("Gemfile", 'w') do |f|
|
28
|
-
f.puts ss
|
29
|
-
f.puts "\n"
|
30
|
-
f.puts sng
|
31
|
-
f.puts "\n"
|
32
|
-
f.puts sg
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def segment_groups(file)
|
37
|
-
groups = file.to_enum(:scan, /(^(group).{0,}(do)$)(\n(.+)){0,}\nend/).map{ Regexp.last_match(0) }
|
38
|
-
ordered_groups = []
|
39
|
-
|
40
|
-
segmented_groups = []
|
41
|
-
|
42
|
-
for i in 0...groups.length
|
43
|
-
segmented_groups[i] = groups[i].split("\n")
|
44
|
-
end
|
45
|
-
|
46
|
-
for i in 0...segmented_groups.length
|
47
|
-
ordered_groups[i] = segmented_groups[i][1,segmented_groups[i].length-2]
|
48
|
-
ordered_groups[i].sort!
|
49
|
-
ordered_groups[i].unshift(segmented_groups[i][0])
|
50
|
-
ordered_groups[i].push(segmented_groups[i].last)
|
51
|
-
ordered_groups[i].push("\n")
|
52
|
-
end
|
53
|
-
return ordered_groups
|
54
|
-
end
|
55
|
-
|
56
|
-
def segment_non_groups(file)
|
57
|
-
non_groups = file.to_enum(:scan, /^((?!(^(group|\t|\s|end|Source).{0,})(\n(.*)){0,}\n).)*$/).map{ Regexp.last_match(0) }
|
58
|
-
sort_segmented_non_groups(non_groups)
|
59
|
-
end
|
60
|
-
|
61
|
-
def segment_source(file)
|
62
|
-
source_group = file.match(/^Source.{0,}/i)
|
63
|
-
end
|
64
|
-
|
65
|
-
def sort_segmented_groups(segmented_groups)
|
66
|
-
ordered_groups = []
|
67
|
-
segmented_groups.each do |segmented_group|
|
68
|
-
temp_arr = segmented_group[1,segmented_group.length-2]
|
69
|
-
temp_arr.sort!
|
70
|
-
sorted << segmented_group[0].split + temp_arr + segmented_group.last.split
|
71
|
-
end
|
72
|
-
return sorted
|
73
|
-
end
|
74
|
-
|
75
|
-
def sort_segmented_non_groups(non_groups)
|
76
|
-
non_groups.sort!
|
77
|
-
non_groups.uniq!
|
78
|
-
non_groups.keep_if{ |el| el != "" && el != "end"}
|
79
|
-
return non_groups
|
80
|
-
end
|
24
|
+
|
81
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alfalfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Nast
|
@@ -10,8 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
and collection functions
|
13
|
+
description: Alfalfa can be used to alphabetize cumbersome gemfiles.
|
15
14
|
email: tommyn@isomedia.com
|
16
15
|
executables: []
|
17
16
|
extensions: []
|
@@ -41,5 +40,5 @@ rubyforge_project: alfalfa
|
|
41
40
|
rubygems_version: 2.2.2
|
42
41
|
signing_key:
|
43
42
|
specification_version: 4
|
44
|
-
summary:
|
43
|
+
summary: gemfile organizer
|
45
44
|
test_files: []
|