Class: Spade::DependencyInstaller

Inherits:
Gem::DependencyInstaller
  • Object
show all
Defined in:
lib/spade/dependency_installer.rb

Instance Method Summary collapse

Instance Method Details

#find_spec_by_name_and_version(gem_name, version = Gem::Requirement.default, prerelease = false) ⇒ Object

Had to overwrite this all just to change the match from /gem$/ to /spd$/



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spade/dependency_installer.rb', line 7

def find_spec_by_name_and_version(gem_name,
                                  version = Gem::Requirement.default,
                                  prerelease = false)
  spec_and_source = nil

  glob = if File::ALT_SEPARATOR then
           gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
         else
           gem_name
         end

  local_gems = Dir["#{glob}*"].sort.reverse

  unless local_gems.empty? then
    local_gems.each do |gem_file|
      next unless gem_file =~ /spd$/
      begin
        spec = Gem::Format.from_file_by_path(gem_file).spec
        spec_and_source = [spec, gem_file]
        break
      rescue SystemCallError, Gem::Package::FormatError
      end
    end
  end

  if spec_and_source.nil? then
    dep = Gem::Dependency.new gem_name, version
    dep.prerelease = true if prerelease
    spec_and_sources = find_gems_with_sources(dep).reverse

    spec_and_source = spec_and_sources.find { |spec, source|
      Gem::Platform.match spec.platform
    }
  end

  if spec_and_source.nil? then
    raise Gem::GemNotFoundException.new(
      "Could not find a valid spd '#{gem_name}' (#{version}) locally or in a repository",
      gem_name, version, @errors)
  end

  @specs_and_sources = [spec_and_source]
end

#install(dep_or_name, version = Gem::Requirement.default) ⇒ Object

Overwrite this to use our custom installer



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/spade/dependency_installer.rb', line 52

def install dep_or_name, version = Gem::Requirement.default
  if String === dep_or_name then
    find_spec_by_name_and_version dep_or_name, version, @prerelease
  else
    dep_or_name.prerelease = @prerelease
    @specs_and_sources = [find_gems_with_sources(dep_or_name).last]
  end

  @installed_gems = []

  gather_dependencies

  @gems_to_install.each do |spec|
    last = spec == @gems_to_install.last
    # HACK is this test for full_name acceptable?
    next if @source_index.any? { |n,_| n == spec.full_name } and not last

    # TODO: make this sorta_verbose so other users can benefit from it
    say "Installing spd #{spec.full_name}" if Gem.configuration.really_verbose

    _, source_uri = @specs_and_sources.assoc spec
    begin
      local_gem_path = Gem::RemoteFetcher.fetcher.download spec, source_uri,
                                                           @cache_dir
    rescue Gem::RemoteFetcher::FetchError
      next if @force
      raise
    end

    inst = Spade::Installer.new local_gem_path,
                              :bin_dir             => @bin_dir,
                              :development         => @development,
                              :env_shebang         => @env_shebang,
                              :force               => @force,
                              :format_executable   => @format_executable,
                              :ignore_dependencies => @ignore_dependencies,
                              :install_dir         => @install_dir,
                              :security_policy     => @security_policy,
                              :source_index        => @source_index,
                              :user_install        => @user_install,
                              :wrappers            => @wrappers

    spec = inst.install

    @installed_gems << spec
  end

  @installed_gems
end