ruby_chopped 0.0.2 → 0.0.3
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.
- data/README +7 -2
- data/bin/ruby_chopped +22 -19
- data/lib/ruby_chopped/version.rb +1 -1
- data/lib/ruby_chopped.rb +34 -5
- metadata +3 -3
data/README
CHANGED
data/bin/ruby_chopped
CHANGED
@@ -2,27 +2,30 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
4
|
require 'ruby_chopped'
|
5
|
-
require '
|
5
|
+
require 'optparse'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
FileUtils.mkdir_p(File.join(folder, "lib"))
|
13
|
-
FileUtils.touch(File.join(folder, "lib", "#{folder}.rb"))
|
14
|
-
File.open("#{folder}/Gemfile", "wb+") do |f|
|
15
|
-
f << RubyChopped.gemfile_string
|
7
|
+
@options = {}
|
8
|
+
parser = OptionParser.new do |o|
|
9
|
+
o.on('-n', '--name [name]', 'name of project to create') do |n|
|
10
|
+
@options[:name] = n
|
16
11
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
o.on('-f', '--force', 'force overwriting existing project') do
|
13
|
+
@options[:force] = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
parser.parse!
|
17
|
+
|
18
|
+
# Allow for old syntax of ruby_chopped new name
|
19
|
+
# At some point we'll do away with this entirely
|
20
|
+
unless @options[:name]
|
21
|
+
if ARGV.shift == "new" && ARGV.first
|
22
|
+
@options[:name] = ARGV.first
|
23
|
+
end
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
puts
|
23
|
-
|
24
|
-
else
|
25
|
-
puts "Unknown Action. Please use 'ruby_chopped new my_new_basket'"
|
26
|
+
unless @options[:name]
|
27
|
+
puts parser
|
28
|
+
exit 1
|
26
29
|
end
|
27
30
|
|
28
|
-
|
31
|
+
RubyChopped.create(@options)
|
data/lib/ruby_chopped/version.rb
CHANGED
data/lib/ruby_chopped.rb
CHANGED
@@ -1,8 +1,37 @@
|
|
1
1
|
require 'rest-client'
|
2
|
+
require 'fileutils'
|
2
3
|
require 'json'
|
3
4
|
|
4
5
|
module RubyChopped
|
5
|
-
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def create(opts={})
|
9
|
+
folder = opts[:name]
|
10
|
+
if File.exist?(folder)
|
11
|
+
unless opts[:force]
|
12
|
+
puts "#{folder} already exists, use -f/--force option to recreate it"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
puts "Creating #{folder} basket..."
|
18
|
+
FileUtils.mkdir_p("#{folder}/lib")
|
19
|
+
|
20
|
+
File.open("#{folder}/lib/#{folder}.rb", "w") {|f| f.puts "# Where the magic happens!" }
|
21
|
+
|
22
|
+
File.open("#{folder}/Gemfile", "wb+") do |f|
|
23
|
+
f << RubyChopped.gemfile_string
|
24
|
+
end
|
25
|
+
|
26
|
+
puts ""
|
27
|
+
puts "Your basket is ready. Open the Gemfile to see what you'll be working with today."
|
28
|
+
|
29
|
+
puts ""
|
30
|
+
puts "You'll want to cd into #{folder} and run 'bundle install' first"
|
31
|
+
puts "Enjoy!"
|
32
|
+
end
|
33
|
+
|
34
|
+
def gemfile_array
|
6
35
|
gas = []
|
7
36
|
gas << "source \"http://rubygems.org\""
|
8
37
|
gas << ""
|
@@ -25,16 +54,16 @@ module RubyChopped
|
|
25
54
|
gas
|
26
55
|
end
|
27
56
|
|
28
|
-
def
|
57
|
+
def gemfile_string
|
29
58
|
gemfile_array.join("\n")
|
30
59
|
end
|
31
60
|
|
32
|
-
def
|
61
|
+
def random_gems(limit=2)
|
33
62
|
gems = fetch_gems
|
34
63
|
gems = pick_gems(gems, limit)
|
35
64
|
end
|
36
65
|
|
37
|
-
def
|
66
|
+
def pick_gems(gems, limit)
|
38
67
|
limit.to_i.times.collect do
|
39
68
|
g = gems.delete_at(rand(gems.size))
|
40
69
|
|
@@ -47,7 +76,7 @@ module RubyChopped
|
|
47
76
|
end
|
48
77
|
end
|
49
78
|
|
50
|
-
def
|
79
|
+
def fetch_gems
|
51
80
|
gems_json = JSON.parse(RestClient.get("http://rubygems.org/api/v1/downloads/top.json", :accepts => :json))
|
52
81
|
gems = gems_json["gems"]
|
53
82
|
gems
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mark McSpadden
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-08-
|
17
|
+
date: 2011-08-22 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|