Class: Verdi::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/verdi/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
11
12
# File 'lib/verdi/runner.rb', line 6

def initialize(command)
  @gem_name, *@versions = command
  @platform = Gem.platforms.last

  @versions ||= [Gem.requirement.default]
  @names_and_versions = @versions.map {|version| "#{@gem_name}-#{version}"}
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/verdi/runner.rb', line 14

def execute
  package_paths = @names_and_versions.map do |name_with_version|
    path = fetch name_with_version
    extract path, name_with_version
    path
  end
  
  command = "git diff --color-words --no-index "+
            "#{@names_and_versions.reverse.join(" ")}"
  system(command)
  FileUtils.rm_rf(package_paths + @names_and_versions)
end

#extract(path, name_with_version) ⇒ Object



47
48
49
50
# File 'lib/verdi/runner.rb', line 47

def extract(path, name_with_version)
  package = Gem::Package.new(path)
  package.extract_files name_with_version
end

#fetch(name_with_version) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/verdi/runner.rb', line 27

def fetch(name_with_version)
  dep = Gem::Dependency.new *name_with_version.split("-")

  specs_and_sources, errors =
    Gem::SpecFetcher.fetcher.spec_for_dependency dep

  if @platform then
    filtered = specs_and_sources.select { |s,| s.platform == @platform }
    specs_and_sources = filtered unless filtered.empty?
  end

  spec, source = specs_and_sources.max_by { |s,| s.version }

  if spec.nil? then
    raise GemNotFound
  end

  source.download spec
end