ruby_chopped 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -6,15 +6,22 @@ Usage
6
6
 
7
7
  gem install ruby_chopped
8
8
 
9
- then
9
+ then to create a new basket that pull 2 of the 50 most popular gems on rubygems.org
10
10
 
11
11
  ruby_chopped --name whyday_basket
12
12
 
13
- or to get more than 2 gems (which is the default)
13
+
14
+ or to get more than 2 gems
14
15
 
15
16
  ruby_chopped -n whyday_basket2 --limit 4
16
17
 
17
- or to view more options
18
+
19
+ or to choose from your locally installed gems instead of rubygems.org
20
+
21
+ ruby_chopped -n whyday_basket2 --installed
22
+
23
+
24
+ or to view more of the great options
18
25
 
19
26
  ruby_chopped
20
27
 
@@ -25,4 +32,5 @@ markmcspadden
25
32
 
26
33
  badboy
27
34
  agile
28
- smnickerson
35
+ smnickerson
36
+ jwarzech
@@ -6,16 +6,25 @@ require 'optparse'
6
6
 
7
7
  @options = {}
8
8
  parser = OptionParser.new do |o|
9
+ # Option: Set Name
9
10
  o.on('-n', '--name [name]', 'name of project to create') do |n|
10
11
  @options[:name] = n
11
12
  end
13
+ # Option: Force overwrite
12
14
  o.on('-f', '--force', 'force overwriting existing project') do
13
15
  @options[:force] = true
14
16
  end
15
-
16
17
  o.on('-l', '--limit [limit]', 'number of gems to add to the basket') do |l|
17
18
  @options[:limit] = l
18
19
  end
20
+ # Option: Select only from locally installed gems
21
+ o.on('-i', '--installed', 'only select gems that are locally installed') do
22
+ @options[:installed_gems] = true
23
+ end
24
+ # Option: Select from all gems
25
+ o.on('-a', '--all', 'select from all existing gems') do
26
+ @options[:all_gems] = true
27
+ end
19
28
  end
20
29
  parser.parse!
21
30
 
@@ -6,6 +6,16 @@ module RubyChopped
6
6
  extend self
7
7
 
8
8
  def create(opts={})
9
+
10
+ # Set pool of gems to fetch from
11
+ if opts[:installed_gems]
12
+ @gem_pool = :installed
13
+ elsif opts[:all_gems]
14
+ @gem_pool = :all
15
+ else
16
+ @gem_pool = :popular
17
+ end
18
+
9
19
  folder = opts[:name]
10
20
  if File.exist?(folder)
11
21
  unless opts[:force]
@@ -38,14 +48,21 @@ module RubyChopped
38
48
 
39
49
  gems = random_gems(limit)
40
50
  gems.each do |g|
41
- # Janky way to pull the name
42
- g = g.first
43
- name = g["full_name"].split(/-\d\.\d\.\d/).first
44
- number = g["number"]
45
- summary = g["summary"]
51
+ # Fetch detailed information for selected gems
52
+ info_json = JSON.parse(RestClient.get("http://rubygems.org/api/v1/gems/#{g}.json", :accepts => :json))
53
+ number = info_json["version"]
54
+ summary = info_json["info"].gsub("\n","\n# ")
55
+ project_uri = info_json["project_uri"]
56
+ documentation_uri = info_json["documentation_uri"]
57
+ wiki_uri = info_json["wiki_uri"]
58
+ mailing_list_uri = info_json["mailing_list_uri"]
46
59
 
47
- gas << "# #{name}: #{summary}"
48
- gas << "gem \"#{name}\", \"#{number}\""
60
+ gas << "# #{g}: #{summary}"
61
+ gas << "# - Project page: #{project_uri}" unless project_uri.nil? || project_uri.empty?
62
+ gas << "# - Documentation: #{documentation_uri}" unless documentation_uri.nil? || documentation_uri.empty?
63
+ gas << "# - Wiki: #{wiki_uri}" unless wiki_uri.nil? || wiki_uri.empty?
64
+ gas << "# - Mailing List: #{mailing_list_uri}" unless mailing_list_uri.nil? || mailing_list_uri.empty?
65
+ gas << "gem \"#{g}\", \"#{number}\""
49
66
  gas << ""
50
67
  end
51
68
 
@@ -68,7 +85,7 @@ module RubyChopped
68
85
  g = gems.delete_at(rand(gems.size))
69
86
 
70
87
  # Skip bundler and rails
71
- if g.first["full_name"][/(bundler|rails)/]
88
+ if g.match(/bundler|rails/)
72
89
  pick_gems(gems, 1).first
73
90
  else
74
91
  g
@@ -77,8 +94,38 @@ module RubyChopped
77
94
  end
78
95
 
79
96
  def fetch_gems
80
- gems_json = JSON.parse(RestClient.get("http://rubygems.org/api/v1/downloads/top.json", :accepts => :json))
81
- gems = gems_json["gems"]
97
+ case @gem_pool
98
+ when :installed
99
+ fetch_local_gems
100
+ when :all
101
+ fetch_all_gems
102
+ when :popular
103
+ fetch_popular_gems
104
+ end
105
+ end
106
+
107
+ def fetch_all_gems
108
+ puts "This might take awhile..."
109
+ gems = Array.new
110
+ gem_list = `gem list --remote`
111
+
112
+ gem_list.split("\n").each { |g| gems << g.split(' ').first }
82
113
  gems
83
114
  end
115
+
116
+ def fetch_local_gems
117
+ gems = Array.new
118
+ gem_list = `gem list`
119
+
120
+ gem_list.split("\n").each { |g| gems << g.split(' ').first }
121
+ gems
122
+ end
123
+
124
+ def fetch_popular_gems
125
+ gems = Array.new
126
+ gems_json = JSON.parse(RestClient.get("http://rubygems.org/api/v1/downloads/top.json", :accepts => :json))
127
+
128
+ gems_json["gems"].each { |g| gems << g.first["full_name"].split(/-\d\.\d\.\d/).first }
129
+ gems.uniq!
130
+ end
84
131
  end
@@ -1,3 +1,3 @@
1
1
  module RubyChopped
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_chopped
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 4
9
- version: 0.0.4
9
+ - 6
10
+ version: 0.0.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mark McSpadden
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-08-22 00:00:00 -05:00
18
+ date: 2011-08-26 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 9
28
30
  segments:
29
31
  - 1
30
32
  - 6
@@ -64,6 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
66
  requirements:
65
67
  - - ">="
66
68
  - !ruby/object:Gem::Version
69
+ hash: 3
67
70
  segments:
68
71
  - 0
69
72
  version: "0"
@@ -72,13 +75,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
75
  requirements:
73
76
  - - ">="
74
77
  - !ruby/object:Gem::Version
78
+ hash: 3
75
79
  segments:
76
80
  - 0
77
81
  version: "0"
78
82
  requirements: []
79
83
 
80
84
  rubyforge_project: ruby_chopped
81
- rubygems_version: 1.3.7
85
+ rubygems_version: 1.5.2
82
86
  signing_key:
83
87
  specification_version: 3
84
88
  summary: Creates a ruby project with two random gems