Class: Jeweler::Commands::CheckDependencies

Inherits:
Object
  • Object
show all
Defined in:
lib/jeweler/commands/check_dependencies.rb

Defined Under Namespace

Classes: MissingDependenciesError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gemspecObject

Returns the value of attribute gemspec.



8
9
10
# File 'lib/jeweler/commands/check_dependencies.rb', line 8

def gemspec
  @gemspec
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/jeweler/commands/check_dependencies.rb', line 8

def type
  @type
end

Class Method Details

.build_for(jeweler) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/jeweler/commands/check_dependencies.rb', line 57

def self.build_for(jeweler)
  command = new

  command.gemspec = jeweler.gemspec

  command
end

Instance Method Details

#dependenciesObject



48
49
50
51
52
53
54
55
# File 'lib/jeweler/commands/check_dependencies.rb', line 48

def dependencies
  case type
  when :runtime, :development
    gemspec.send("#{type}_dependencies")
  else
    gemspec.dependencies
  end
end

#find_missing_dependenciesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jeweler/commands/check_dependencies.rb', line 25

def find_missing_dependencies
  if Gem::Specification.respond_to?(:find_by_name)
    dependencies.select do |dependency|
      begin
        spec = Gem::Specification.find_by_name(dependency.name, *dependency.requirement.as_list)
        spec.activate if spec
        !spec
      rescue LoadError => e
        true
      end
    end
  else
    dependencies.select do |dependency|
      begin
        Gem.activate dependency.name, *dependency.requirement.as_list
        false
      rescue LoadError => e
        true
      end
    end
  end
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jeweler/commands/check_dependencies.rb', line 10

def run
  missing_dependencies = find_missing_dependencies

  if missing_dependencies.empty?
    puts "#{type || 'All'} dependencies seem to be installed."
  else
    puts 'Missing some dependencies. Install them with the following commands:'
    missing_dependencies.each do |dependency|
      puts %(\tgem install #{dependency.name} --version "#{dependency.requirement}")
    end

    abort "Run the specified gem commands before trying to run this again: {$PROGRAM_NAME} #{ARGV.join(' ')}"
  end
end