gem-dependent 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gem-dependent}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-11-03}
12
+ s.date = %q{2010-11-04}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.files = [
15
15
  "Gemfile",
@@ -6,7 +6,8 @@ module Gem
6
6
  VERSION = File.read( File.join(File.dirname(__FILE__),'..','..','VERSION') ).strip
7
7
 
8
8
  def self.find(gem, options={})
9
- specs_and_sources = with_changed_source(options[:source]) do
9
+ # get all gems
10
+ specs_and_sources = with_changed_gem_source(options[:source]) do
10
11
  all_specs_and_sources
11
12
  end
12
13
 
@@ -14,50 +15,60 @@ module Gem
14
15
  specs_and_sources = specs_and_sources.first(options[:fetch_limit])
15
16
  end
16
17
 
17
- puts "Downloading specs for #{specs_and_sources.size} gems" if options[:progress]
18
-
19
- # fetch dependencies
20
- gem_names_and_dependencies = Parallel.map(specs_and_sources, :in_processes => 20) do |spec_tuple, source_uri|
21
- if options[:progress]
22
- print '.'
23
- $stdout.flush if rand(20) == 0 # make progress visible
24
- end
25
- name = spec_tuple.first
26
- dependencies = dependencies(spec_tuple, source_uri)
27
- [name, dependencies]
18
+ if options[:progress]
19
+ puts "Downloading specs for #{specs_and_sources.size} gems"
28
20
  end
29
21
 
22
+ gems_and_dependencies = fetch_all_dependencies(specs_and_sources) do
23
+ print_dot if options[:progress]
24
+ end
30
25
  print "\n" if options[:progress]
31
26
 
32
- # select those that depend on #{gem}
33
- gem_names_and_dependencies.map do |_, dependencies|
34
- found = dependencies.select{|d| d.name == gem}
35
- next if found.empty?
36
- [_, found]
37
- end.compact
27
+ select_dependent(gems_and_dependencies, gem)
38
28
  end
39
29
 
40
30
  private
41
31
 
42
- # dependencies for given gem
43
- def self.dependencies(spec_tuple, source_uri)
32
+ def self.fetch_all_dependencies(specs_and_sources)
33
+ Parallel.map(specs_and_sources, :in_processes => 20) do |spec, source|
34
+ yield if block_given?
35
+ name = spec.first
36
+ dependencies = fetch_dependencies(spec, source)
37
+ [name, dependencies]
38
+ end
39
+ end
40
+
41
+ def self.fetch_dependencies(spec, source)
44
42
  begin
45
43
  fetcher = Gem::SpecFetcher.fetcher
46
- fetcher.fetch_spec(spec_tuple, URI.parse(source_uri)).dependencies
44
+ fetcher.fetch_spec(spec, URI.parse(source)).dependencies
47
45
  rescue Gem::RemoteFetcher::FetchError, Zlib::DataError => e
48
46
  $stderr.puts e
49
47
  []
50
48
  end
51
49
  end
52
50
 
51
+ def self.select_dependent(gems_and_dependencies, gem)
52
+ gems_and_dependencies.map do |name, dependencies|
53
+ matching_dependencies = dependencies.select{|d| d.name == gem }
54
+ next if matching_dependencies.empty?
55
+ [name, matching_dependencies]
56
+ end.compact
57
+ end
58
+
59
+ def self.print_dot
60
+ print '.'
61
+ $stdout.flush if rand(20) == 0 # make progress visible
62
+ end
63
+
53
64
  def self.all_specs_and_sources
54
65
  fetcher = Gem::SpecFetcher.fetcher
55
66
  all = true
56
67
  matching_platform = false
57
68
  prerelease = false
58
- name = Gem::Dependency.new(//i, Gem::Requirement.default)
59
- specs_and_sources = fetcher.find_matching name, all, matching_platform, prerelease
60
- uniq_by(specs_and_sources){|a|a.first.first}
69
+ matcher = Gem::Dependency.new(//, Gem::Requirement.default) # any name, any version
70
+ specs_and_sources = fetcher.find_matching matcher, all, matching_platform, prerelease
71
+ uniq_by(specs_and_sources){|a| a.first.first }
61
72
  end
62
73
 
63
74
  # get unique elements from an array (last found is used)
@@ -74,7 +85,7 @@ module Gem
74
85
  values
75
86
  end
76
87
 
77
- def self.with_changed_source(sources)
88
+ def self.with_changed_gem_source(sources)
78
89
  sources = [*sources].compact
79
90
  if sources.empty?
80
91
  yield
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-dependent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-03 00:00:00 +01:00
18
+ date: 2010-11-04 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency