Module: Gem::Portage::GemSpecFetcher

Included in:
EbuildCommand, InstallWithPortage, UpdateWithPortage
Defined in:
lib/g-gem/spec_fetcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.LocalOrRemote(domain) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/g-gem/spec_fetcher.rb', line 4

def LocalOrRemote(domain)
  Module.new do 
    define_method(:local?) do 
      domain == :local || domain == :both
    end
    define_method(:remote?) do
      domain == :remote || domain == :both
    end
  end 
end

Instance Method Details

#fetch_local(dependency) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/g-gem/spec_fetcher.rb', line 20

def fetch_local(dependency)
  dir = dependency.respond_to?(:origin_dir) ? dependency.origin_dir : Dir.pwd
  file = Gem::Portage::Utils::gem_file_for(dependency, dir)
  raise "Gem for #{dependency} not found" unless file
  spec = Gem::Format.from_file_by_path(file).spec
  spec.singleton_eval do 
    define_method(:fetched_from) { file }
  end
  spec.extend LocalOrRemote(:local)
end

#fetch_remote(dependency) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/g-gem/spec_fetcher.rb', line 31

def fetch_remote(dependency)
  remote_installer = Gem::RemoteInstaller.new
  remote_source_index = remote_installer.source_index_hash
  fetcher_proc = lambda do |dep|
    spec, uri = remote_installer.find_gem_to_install(dep.name, 
                                                     dep.version_requirements,
                                                     remote_source_index)
    spec.singleton_eval do 
      define_method(:fetched_from) { uri }
    end
    spec.extend LocalOrRemote(:remote)
  end
  singleton_eval do 
    define_method(:fetch_remote, &fetcher_proc)
  end
  fetch_remote(dependency)
end

#fetch_spec(dependency) ⇒ Object



72
73
74
# File 'lib/g-gem/spec_fetcher.rb', line 72

def fetch_spec(dependency)
  spec_fetcher[dependency]
end

#local_fetcherObject



49
50
51
# File 'lib/g-gem/spec_fetcher.rb', line 49

def local_fetcher
  method(:fetch_local).extend LocalOrRemote(:local)
end

#LocalOrRemote(domain) ⇒ Object



16
17
18
# File 'lib/g-gem/spec_fetcher.rb', line 16

def LocalOrRemote(domain)
  GemSpecFetcher.LocalOrRemote(domain)
end

#remote_fetcherObject



53
54
55
# File 'lib/g-gem/spec_fetcher.rb', line 53

def remote_fetcher
  method(:fetch_remote).extend LocalOrRemote(:remote)
end

#spec_fetcher(domain = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/g-gem/spec_fetcher.rb', line 57

def spec_fetcher(domain=nil)
  domain = domain ? Object.new.extend(LocalOrRemote(domain)) : self
  if domain.local? ^ domain.remote?
    domain.local? ? local_fetcher : remote_fetcher
  else
    lambda do |dependency|
      begin
        local_fetcher[dependency]
      rescue
        remote_fetcher[dependency]
      end
    end.extend LocalOrRemote(:both)
  end
end