ruby/lib/rubygems/specification.rb
##
# Checks that dependencies use requirements as we recommend.  Warnings are
# issued when dependencies are open-ended or overly strict for semantic
# versioning.
Checks that dependencies use requirements as we recommend.  Warnings are
issued when dependencies are open-ended or overly strict for semantic
versioning.
Checks that dependencies use requirements as we recommend . Warnings are issued when dependencies are open - ended or overly strict for semantic versioning .
def validate_dependencies 
    seen = Gem::Dependency::TYPES.inject({}) { |types, type| types.merge({ type => {}}) }
    error_messages = []
    warning_messages = []
    dependencies.each do |dep|
      if prev = seen[dep.type][dep.name] then
        error_messages << <<-MESSAGE
duplicate dependency on #{dep}, (#{prev.requirement}) use:
    add_#{dep.type}_dependency '#{dep.name}', '#{dep.requirement}', '#{prev.requirement}'
        MESSAGE
      end
      seen[dep.type][dep.name] = dep
      prerelease_dep = dep.requirements_list.any? do |req|
        Gem::Requirement.new(req).prerelease?
      end
      warning_messages << "prerelease dependency on #{dep} is not recommended" if
        prerelease_dep && !version.prerelease?
      overly_strict = dep.requirement.requirements.length == 1 &&
        dep.requirement.requirements.any? do |op, version|
          op == '~>' and
            not version.prerelease? and
            version.segments.length > 2 and
            version.segments.first != 0
        end
      if overly_strict then
        _, dep_version = dep.requirement.requirements.first
        base = dep_version.segments.first 2
        warning_messages << <<-WARNING
pessimistic dependency on #{dep} may be overly strict
  if #{dep.name} is semantically versioned, use:
    add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}', '>= #{dep_version}'
        WARNING
      end
      open_ended = dep.requirement.requirements.all? do |op, version|
        not version.prerelease? and (op == '>' or op == '>=')
      end
      if open_ended then
        op, dep_version = dep.requirement.requirements.first
        base = dep_version.segments.first 2
        bugfix = if op == '>' then
                   ", '> #{dep_version}'"
                 elsif op == '>=' and base != dep_version.segments then
                   ", '>= #{dep_version}'"
                 end
        warning_messages << <<-WARNING
open-ended dependency on #{dep} is not recommended
  if #{dep.name} is semantically versioned, use:
    add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}
        WARNING
      end
    end
    if error_messages.any?
      raise Gem::InvalidSpecificationException, error_messages.join
    end
    if warning_messages.any?
      warning_messages.each { |warning_message| warning warning_message }
    end
  end
def validate_dependencies seen = Gem :: Dependency :: TYPES . inject ( { } ) { | types , type | types . merge ( { type => { } } ) } error_messages = [ ] warning_messages = [ ] dependencies . each do | dep | if prev = seen [ dep . type ] [ dep . name ] then error_messages << <<-MESSAGE 
duplicate dependency on  #{ dep } , ( #{ prev . requirement } ) use:
    add_ #{ dep . type } _dependency ' #{ dep . name } ', ' #{ dep . requirement } ', ' #{ prev . requirement } '
         MESSAGE end seen [ dep . type ] [ dep . name ] = dep prerelease_dep = dep . requirements_list . any? do | req | Gem :: Requirement . new ( req ) . prerelease? end warning_messages << "prerelease dependency on #{dep} is not recommended" if prerelease_dep && ! version . prerelease? overly_strict = dep . requirement . requirements . length == 1 && dep . requirement . requirements . any? do | op , version | op == '~>' and not version . prerelease? and version . segments . length > 2 and version . segments . first != 0 end if overly_strict then _ , dep_version = dep . requirement . requirements . first base = dep_version . segments . first 2 warning_messages << <<-WARNING 
pessimistic dependency on  #{ dep }  may be overly strict
  if  #{ dep . name }  is semantically versioned, use:
    add_ #{ dep . type } _dependency ' #{ dep . name } ', '~>  #{ base . join '.' } ', '>=  #{ dep_version } '
         WARNING end open_ended = dep . requirement . requirements . all? do | op , version | not version . prerelease? and ( op == '>' or op == '>=' ) end if open_ended then op , dep_version = dep . requirement . requirements . first base = dep_version . segments . first 2 bugfix = if op == '>' then ", '> #{dep_version}'" elsif op == '>=' and base != dep_version . segments then ", '>= #{dep_version}'" end warning_messages << <<-WARNING 
open-ended dependency on  #{ dep }  is not recommended
  if  #{ dep . name }  is semantically versioned, use:
    add_ #{ dep . type } _dependency ' #{ dep . name } ', '~>  #{ base . join '.' } ' #{ bugfix } WARNING end end if error_messages . any? raise Gem :: InvalidSpecificationException , error_messages . join end if warning_messages . any? warning_messages . each { | warning_message | warning warning_message } end end
Checks that dependencies use requirements as we recommend.
Checks that dependencies use requirements as we recommend .
# :nodoc: # NOTE: see REFACTOR note in Gem::Dependency about types - this might be brittle