ruby_chopped 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -8,11 +8,16 @@ gem install ruby_chopped
8
8
 
9
9
  then
10
10
 
11
- ruby_chopped new whyday_basket
11
+ ruby_chopped --name whyday_basket
12
+
13
+ or to view more options
14
+
15
+ ruby_chopped
12
16
 
13
17
 
14
18
  Contributors
15
19
 
16
20
  markmcspadden
17
21
 
18
- badboy
22
+ badboy
23
+ agile
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 'fileutils'
5
+ require 'optparse'
6
6
 
7
- if "new" == ARGV.shift && ARGV.first
8
- folder = ARGV.shift
9
-
10
- puts "Creating #{folder} basket..."
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
- puts ""
19
- puts "Your basket is ready. Open the Gemfile to see what you'll be working with today."
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
- puts ""
22
- puts "You'll want to cd into #{folder} and run 'bundle install' first"
23
- puts "Enjoy!"
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
- exit!
31
+ RubyChopped.create(@options)
@@ -1,3 +1,3 @@
1
1
  module RubyChopped
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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
- def self.gemfile_array
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 self.gemfile_string
57
+ def gemfile_string
29
58
  gemfile_array.join("\n")
30
59
  end
31
60
 
32
- def self.random_gems(limit=2)
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 self.pick_gems(gems, limit)
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 self.fetch_gems
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
- - 2
9
- version: 0.0.2
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-19 00:00:00 -05:00
17
+ date: 2011-08-22 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency