gem_stats 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gem_stats.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'rake/testtask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the get_or_build gem.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
data/bin/fetchgemstats ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gem_stats'
3
+
4
+ puts 'Starting fetching...'
5
+ start = Time.now
6
+ GemStats::Fetcher.fetch_and_safe
7
+ puts "Finished in #{(Tine.now - start).round(0)} second(s)"
data/bin/geminfo ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gem_stats'
3
+
4
+ ARGV.each do |gem_name|
5
+ @gem_info = GemStats::GemInfo.new(gem_name)
6
+
7
+ clients = @gem_info.clients
8
+ puts "Dependencies in runtime mode: #{clients.map(&:name).join(', ')}"
9
+ puts "Total: #{clients.count}"
10
+
11
+ clients = @gem_info.clients(:development)
12
+ puts "Dependencies in development mode: #{clients.map(&:name).join(', ')}"
13
+ puts "Total: #{clients.count}"
14
+ end
data/config/mongo.yml ADDED
@@ -0,0 +1,2 @@
1
+ host: localhost
2
+ database: gem_stats
data/gem_stats.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gem_stats/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gem_stats"
7
+ s.version = GemStats::VERSION
8
+ s.authors = ["Andrey Koleshko"]
9
+ s.email = ["ka8725@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Fetch full statistic for the given gem name}
12
+ s.description = %q{Just put gemstats your_gem_name and have a pleasure to see full statistic for this gem}
13
+
14
+ s.rubyforge_project = "gem_stats"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rake"
23
+ s.add_runtime_dependency "json"
24
+ s.add_runtime_dependency "mongo_mapper"
25
+ s.add_runtime_dependency "bson_ext"
26
+ end
@@ -0,0 +1,8 @@
1
+ module GemStats
2
+ module Connection
3
+ def self.connect
4
+ MongoMapper.connection = Mongo::Connection.new('localhost')
5
+ MongoMapper.database = 'gem_stats'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems/spec_fetcher'
2
+
3
+ module GemStats
4
+ class Fetcher
5
+ def self.list(all_versions = false, prerelease = false)
6
+ @gem_list ||= ::Gem::SpecFetcher.new.list(all_versions, prerelease).values.flatten(1)
7
+ end
8
+
9
+ def self.list_names
10
+ @list_name ||= list.map(&:first)
11
+ end
12
+
13
+ def self.fetch_and_safe
14
+ threads = []
15
+ list_names.each do |name|
16
+ threads << Thread.new(name) { |name| GemInfo.new(name).save }
17
+ if threads.count == 50
18
+ threads.each(&:join)
19
+ threads = []
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'mongo_mapper'
2
+
3
+ module GemStats
4
+ class Gem
5
+ include MongoMapper::Document
6
+
7
+ key :name, String
8
+ key :runtime_dependencies, Array
9
+ key :development_dependencies, Array
10
+ key :version, String
11
+ key :downloads, Integer
12
+ key :version_downloads, String
13
+ key :authors, String
14
+ key :info, String
15
+ key :project_uri, String
16
+ key :gem_uri, String
17
+ key :homepage_uri, String
18
+ key :wiki_uri, String
19
+ key :documentation_uri, String
20
+ key :mailing_list_uri, String
21
+ key :source_code_uri, String
22
+ key :bug_tracker_uri, String
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ module GemStats
5
+ class GemInfo
6
+ API_URL = "https://rubygems.org/api/v1/gems/"
7
+ REQUEST_FORMAT = 'json'
8
+
9
+ attr_reader :name
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ end
14
+
15
+ def info
16
+ @info ||= JSON.load open("#{API_URL}#{@name}.#{REQUEST_FORMAT}").read
17
+ end
18
+
19
+ def dependencies(env = 'runtime')
20
+ @dependencies ||= {}
21
+ @dependencies[env.to_s] ||= info['dependencies'][env.to_s].inject([]) { |sum, gem| sum << gem['name'] }
22
+ end
23
+
24
+ def clients(env = 'runtime')
25
+ Gem.where("#{env}_dependencies" => @name).all
26
+ end
27
+
28
+ def save
29
+ log @name
30
+ gem = Gem.find_by_name(@name) || Gem.new
31
+ gem.attributes = {:name => @name,
32
+ :runtime_dependencies => dependencies,
33
+ :development_dependencies => dependencies('development'),
34
+ :version => info['version'],
35
+ :downloads => info['downloads'],
36
+ :version_downloads => info['version_downloads'],
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
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module GemStats
2
+ VERSION = "0.0.1"
3
+ end
data/lib/gem_stats.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "gem_stats/version"
2
+ require "gem_stats/gem"
3
+ require "gem_stats/gem_info"
4
+ require "gem_stats/fetcher"
5
+ require "gem_stats/connection"
6
+
7
+ module GemStats
8
+ end
9
+
10
+ GemStats::Connection.connect
11
+
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class FetcherTest < Test::Unit::TestCase
4
+ include GemStats
5
+
6
+ def test_fetch_list_gems
7
+ assert_not_nil Fetcher.list
8
+ end
9
+
10
+ def test_size_of_fetcher_list
11
+ assert_equal Fetcher.list.count, Fetcher.list_names.count
12
+ end
13
+
14
+ def test_fetch_and_save
15
+ assert_equal true, Fetcher.respond_to?(:fetch_and_safe)
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class GemInfoTest < Test::Unit::TestCase
4
+ def setup
5
+ @gem = GemStats::GemInfo.new('get_or_build')
6
+ end
7
+
8
+ def test_fetch
9
+ assert_not_nil @gem.info
10
+ end
11
+
12
+ def test_dependencies
13
+ assert_equal [], @gem.dependencies
14
+ assert_equal ["actionpack", "activerecord", "rake", "sqlite3"].sort, @gem.dependencies(:development).sort
15
+ assert_equal [], @gem.dependencies(:runtime)
16
+ end
17
+
18
+ def test_clients
19
+ assert_equal [], @gem.clients.to_a
20
+ assert_equal [], @gem.clients(:development).to_a
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require 'gem_stats'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Koleshko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70259170946480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70259170946480
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70259170946020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70259170946020
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongo_mapper
38
+ requirement: &70259170945420 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70259170945420
47
+ - !ruby/object:Gem::Dependency
48
+ name: bson_ext
49
+ requirement: &70259170944820 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70259170944820
58
+ description: Just put gemstats your_gem_name and have a pleasure to see full statistic
59
+ for this gem
60
+ email:
61
+ - ka8725@gmail.com
62
+ executables:
63
+ - fetchgemstats
64
+ - geminfo
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - Rakefile
71
+ - bin/fetchgemstats
72
+ - bin/geminfo
73
+ - config/mongo.yml
74
+ - gem_stats.gemspec
75
+ - lib/gem_stats.rb
76
+ - lib/gem_stats/connection.rb
77
+ - lib/gem_stats/fetcher.rb
78
+ - lib/gem_stats/gem.rb
79
+ - lib/gem_stats/gem_info.rb
80
+ - lib/gem_stats/version.rb
81
+ - test/fetcher_test.rb
82
+ - test/gem_info_test.rb
83
+ - test/test_helper.rb
84
+ homepage: ''
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -2815935118913676328
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -2815935118913676328
108
+ requirements: []
109
+ rubyforge_project: gem_stats
110
+ rubygems_version: 1.8.10
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Fetch full statistic for the given gem name
114
+ test_files:
115
+ - test/fetcher_test.rb
116
+ - test/gem_info_test.rb
117
+ - test/test_helper.rb