lib/rubygems/specification_policy.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 
    warning_messages = []
    @specification.dependencies.each do |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 && !@specification.version.prerelease?
      open_ended = dep.requirement.requirements.all? do |op, version|
        not version.prerelease? and (op == '>' or op == '>=')
      end
      if open_ended
        op, dep_version = dep.requirement.requirements.first
        segments = dep_version.segments
        base = segments.first 2
        recommendation = if (op == '>' || op == '>=') && segments == [0]
                           "  use a bounded requirement, such as '~> x.y'"
                         else
                           bugfix = if op == '>'
                                      ", '> #{dep_version}'"
                                    elsif op == '>=' and base != segments
                                      ", '>= #{dep_version}'"
                                    end
                           "  if #{dep.name} is semantically versioned, use:\n" \
                           "    add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}"
                         end
        warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
      end
    end
    if warning_messages.any?
      warning_messages.each {|warning_message| warning warning_message }
    end
  end
def validate_dependencies warning_messages = [ ] @specification . dependencies . each do | 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 && ! @specification . version . prerelease? open_ended = dep . requirement . requirements . all? do | op , version | not version . prerelease? and ( op == '>' or op == '>=' ) end if open_ended op , dep_version = dep . requirement . requirements . first segments = dep_version . segments base = segments . first 2 recommendation = if ( op == '>' || op == '>=' ) && segments == [ 0 ] "  use a bounded requirement, such as '~> x.y'" else bugfix = if op == '>' ", '> #{dep_version}'" elsif op == '>=' and base != segments ", '>= #{dep_version}'" end "  if #{dep.name} is semantically versioned, use:\n" "    add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}" end warning_messages << [ "open-ended dependency on #{dep} is not recommended" , recommendation ] . join ( "\n" ) + "\n" end 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: