gem_stats 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +0 -1
- data/bin/fetchgemstats +16 -2
- data/config/database.yml +2 -0
- data/gem_stats.gemspec +1 -0
- data/lib/gem_stats/connection.rb +14 -3
- data/lib/gem_stats/fetcher.rb +13 -3
- data/lib/gem_stats/gem.rb +20 -2
- data/lib/gem_stats/gem_info.rb +14 -25
- data/lib/gem_stats/version.rb +1 -1
- data/lib/gem_stats.rb +0 -3
- data/test/fetcher_test.rb +6 -4
- data/test/gem_info_test.rb +1 -0
- metadata +24 -13
- data/config/mongo.yml +0 -2
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/bin/fetchgemstats
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'gem_stats'
|
3
|
+
require 'optparse'
|
3
4
|
|
4
|
-
puts 'Starting fetching...'
|
5
5
|
start = Time.now
|
6
|
+
|
7
|
+
options = {:config => {'development' => {}, 'production' => {}}, :env => 'development'}
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = 'Usage: fetchgemstats [options]'
|
11
|
+
opts.on('-e', '--env [environment]', 'Default is development environment') { |opt| options[:env] = 'production' }
|
12
|
+
opts.on('-u', '--uri [mongo db URI]',
|
13
|
+
'Pattern: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]') { |opt| options[:config][options[:env]]['uri'] = opt }
|
14
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
15
|
+
puts opts
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
GemStats::Connection.connect(options[:config][options[:env]].empty? ? {} : options)
|
6
21
|
GemStats::Fetcher.fetch_and_safe
|
7
|
-
puts "Finished in #{(Tine.now - start).round(0)} second(s)"
|
data/config/database.yml
ADDED
data/gem_stats.gemspec
CHANGED
data/lib/gem_stats/connection.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
1
3
|
module GemStats
|
2
4
|
module Connection
|
3
|
-
def self.connect
|
4
|
-
|
5
|
-
|
5
|
+
def self.connect(options = {})
|
6
|
+
if options.empty?
|
7
|
+
env, path = defined?(Rails)? [Rails.env, [Rails.root, 'config/database.yml']] :
|
8
|
+
[ENV['ENV'] || 'development', File.expand_path('../../../config/database.yml', __FILE__)]
|
9
|
+
get_config(path) {|config| MongoMapper.setup(config, env) }
|
10
|
+
else
|
11
|
+
MongoMapper.setup(options[:config], options[:env])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_config(*path)
|
16
|
+
yield YAML::load(ERB.new(File.read File.join(path)).result)
|
6
17
|
end
|
7
18
|
end
|
8
19
|
end
|
data/lib/gem_stats/fetcher.rb
CHANGED
@@ -1,24 +1,34 @@
|
|
1
1
|
require 'rubygems/spec_fetcher'
|
2
|
+
require 'progressbar'
|
2
3
|
|
3
4
|
module GemStats
|
4
5
|
class Fetcher
|
6
|
+
@@bulk_number = 50
|
7
|
+
cattr_accessor :bulk_number
|
8
|
+
|
5
9
|
def self.list(all_versions = false, prerelease = false)
|
6
10
|
@gem_list ||= ::Gem::SpecFetcher.new.list(all_versions, prerelease).values.flatten(1)
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.list_names
|
10
|
-
@list_name ||= list.map(&:first)
|
14
|
+
@list_name ||= list.map(&:first).uniq.compact
|
11
15
|
end
|
12
16
|
|
13
17
|
def self.fetch_and_safe
|
18
|
+
pbar = ProgressBar.new("Fetching gems", list.count)
|
19
|
+
pbar.bar_mark = '#'
|
14
20
|
threads = []
|
15
|
-
list_names.
|
21
|
+
list_names.each_with_index do |name, index|
|
16
22
|
threads << Thread.new(name) { |name| GemInfo.new(name).save }
|
17
|
-
if threads.count ==
|
23
|
+
if threads.count == @@bulk_number
|
18
24
|
threads.each(&:join)
|
19
25
|
threads = []
|
26
|
+
pbar.inc(bulk_number)
|
20
27
|
end
|
21
28
|
end
|
29
|
+
threads.each(&:join)
|
30
|
+
pbar.inc(bulk_number)
|
31
|
+
pbar.finish
|
22
32
|
end
|
23
33
|
end
|
24
34
|
end
|
data/lib/gem_stats/gem.rb
CHANGED
@@ -5,8 +5,7 @@ module GemStats
|
|
5
5
|
include MongoMapper::Document
|
6
6
|
|
7
7
|
key :name, String
|
8
|
-
key :
|
9
|
-
key :development_dependencies, Array
|
8
|
+
key :dependencies, Hash
|
10
9
|
key :version, String
|
11
10
|
key :downloads, Integer
|
12
11
|
key :version_downloads, String
|
@@ -20,5 +19,24 @@ module GemStats
|
|
20
19
|
key :mailing_list_uri, String
|
21
20
|
key :source_code_uri, String
|
22
21
|
key :bug_tracker_uri, String
|
22
|
+
|
23
|
+
# to generate pretty url for rails
|
24
|
+
def to_param
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gem_info
|
29
|
+
@gem_info ||= GemInfo.new(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
%w(runtime development).each do |env|
|
33
|
+
define_method "#{env}_dependencies" do
|
34
|
+
dependencies[env]
|
35
|
+
end
|
36
|
+
|
37
|
+
define_method "#{env}_dependents" do
|
38
|
+
eval "@#{env}_dependents ||= gem_info.clients('#{env}')"
|
39
|
+
end
|
40
|
+
end
|
23
41
|
end
|
24
42
|
end
|
data/lib/gem_stats/gem_info.rb
CHANGED
@@ -13,42 +13,31 @@ module GemStats
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def info
|
16
|
-
@info
|
16
|
+
return @info if defined?(@info)
|
17
|
+
begin
|
18
|
+
@info ||= JSON.load open("#{API_URL}#{@name}.#{REQUEST_FORMAT}").read
|
19
|
+
rescue OpenURI::HTTPError => e
|
20
|
+
@info = nil
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
def dependencies(env = 'runtime')
|
20
25
|
@dependencies ||= {}
|
21
|
-
@dependencies[env.to_s] ||= info['dependencies'][env.to_s].inject([]) { |
|
26
|
+
@dependencies[env.to_s] ||= info['dependencies'][env.to_s].inject([]) { |list, gem| list << gem['name'] }
|
22
27
|
end
|
23
28
|
|
24
29
|
def clients(env = 'runtime')
|
25
|
-
Gem.where("
|
30
|
+
Gem.where("dependencies.#{env}.name" => @name).all
|
26
31
|
end
|
27
32
|
|
28
33
|
def save
|
29
|
-
log @name
|
30
34
|
gem = Gem.find_by_name(@name) || Gem.new
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
:authors => info['authors'],
|
38
|
-
:info => info['info'],
|
39
|
-
:project_uri => info['project_uri'],
|
40
|
-
:gem_uri => info['gem_uri'],
|
41
|
-
:homepage_uri => info['homepage_uri'],
|
42
|
-
:wiki_uri => info['wiki_uri'],
|
43
|
-
:documentation_uri => info['documentation_uri'],
|
44
|
-
:mailing_list_uri => info['mailing_list_uri'],
|
45
|
-
:source_code_uri => info['source_code_uri'],
|
46
|
-
:bug_tracker_uri => info['bug_tracker_uri']}
|
47
|
-
gem.save
|
48
|
-
end
|
49
|
-
|
50
|
-
def log(message)
|
51
|
-
puts message
|
35
|
+
if info
|
36
|
+
gem.attributes = info
|
37
|
+
gem.save
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
52
41
|
end
|
53
42
|
end
|
54
43
|
end
|
data/lib/gem_stats/version.rb
CHANGED
data/lib/gem_stats.rb
CHANGED
data/test/fetcher_test.rb
CHANGED
@@ -7,11 +7,13 @@ class FetcherTest < Test::Unit::TestCase
|
|
7
7
|
assert_not_nil Fetcher.list
|
8
8
|
end
|
9
9
|
|
10
|
-
def test_size_of_fetcher_list
|
11
|
-
assert_equal Fetcher.list.count, Fetcher.list_names.count
|
12
|
-
end
|
13
|
-
|
14
10
|
def test_fetch_and_save
|
15
11
|
assert_equal true, Fetcher.respond_to?(:fetch_and_safe)
|
16
12
|
end
|
13
|
+
|
14
|
+
def test_bulk_number
|
15
|
+
assert_equal 50, Fetcher.bulk_number
|
16
|
+
Fetcher.bulk_number = 100
|
17
|
+
assert_equal 100, Fetcher.bulk_number
|
18
|
+
end
|
17
19
|
end
|
data/test/gem_info_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ 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
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70130075293200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70130075293200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70130075292220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70130075292220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mongo_mapper
|
38
|
-
requirement: &
|
38
|
+
requirement: &70130075290980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70130075290980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bson_ext
|
49
|
-
requirement: &
|
49
|
+
requirement: &70130075290060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,18 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70130075290060
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: ruby-progressbar
|
60
|
+
requirement: &70130075288840 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70130075288840
|
58
69
|
description: Just put gemstats your_gem_name and have a pleasure to see full statistic
|
59
70
|
for this gem
|
60
71
|
email:
|
@@ -70,7 +81,7 @@ files:
|
|
70
81
|
- Rakefile
|
71
82
|
- bin/fetchgemstats
|
72
83
|
- bin/geminfo
|
73
|
-
- config/
|
84
|
+
- config/database.yml
|
74
85
|
- gem_stats.gemspec
|
75
86
|
- lib/gem_stats.rb
|
76
87
|
- lib/gem_stats/connection.rb
|
@@ -95,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
106
|
version: '0'
|
96
107
|
segments:
|
97
108
|
- 0
|
98
|
-
hash: -
|
109
|
+
hash: -402065578050743399
|
99
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
111
|
none: false
|
101
112
|
requirements:
|
@@ -104,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
115
|
version: '0'
|
105
116
|
segments:
|
106
117
|
- 0
|
107
|
-
hash: -
|
118
|
+
hash: -402065578050743399
|
108
119
|
requirements: []
|
109
120
|
rubyforge_project: gem_stats
|
110
121
|
rubygems_version: 1.8.10
|
data/config/mongo.yml
DELETED