Sha256: ee974ba3244f3b0c502dc239e4aaf83f28a6a193f310a393aac50411aae90b91

Contents?: true

Size: 1.75 KB

Versions: 17

Compression:

Stored size: 1.75 KB

Contents

class Juwelier
  module Commands
    class CheckDependencies
      class MissingDependenciesError < RuntimeError
        attr_accessor :dependencies, :type
      end

      attr_accessor :gemspec, :type

      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 %Q{\tgem install #{dependency.name} --version "#{dependency.requirement.to_s}"}
          end

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

      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

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

      def self.build_for(juwelier)
        command = new

        command.gemspec = juwelier.gemspec

        command
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
juwelier-2.4.9 lib/juwelier/commands/check_dependencies.rb
juwelier-2.4.7 lib/juwelier/commands/check_dependencies.rb
juwelier-2.4.6 lib/juwelier/commands/check_dependencies.rb
juwelier-2.4.5 lib/juwelier/commands/check_dependencies.rb
juwelier-2.4.4 lib/juwelier/commands/check_dependencies.rb
juwelier-2.4.1 lib/juwelier/commands/check_dependencies.rb
juwelier-2.4.0 lib/juwelier/commands/check_dependencies.rb
juwelier-2.3.6 lib/juwelier/commands/check_dependencies.rb
juwelier-2.3.4 lib/juwelier/commands/check_dependencies.rb
juwelier-2.3.2 lib/juwelier/commands/check_dependencies.rb
juwelier-2.3.0 lib/juwelier/commands/check_dependencies.rb
juwelier-2.2.3 lib/juwelier/commands/check_dependencies.rb
juwelier-2.2.1 lib/juwelier/commands/check_dependencies.rb
juwelier-2.1.3 lib/juwelier/commands/check_dependencies.rb
juwelier-2.1.2 lib/juwelier/commands/check_dependencies.rb
juwelier-2.1.1 lib/juwelier/commands/check_dependencies.rb
juwelier-2.1.0 lib/juwelier/commands/check_dependencies.rb