In Files

  • rubygems/requirement.rb

Class/Module Index [+]

Quicksearch

Gem::Requirement

Public Class Methods

create(input) click to toggle source

REFACTOR: There's no reason that this can't be unified with .new. .new is the standard Ruby factory method.

 
               # File rubygems/requirement.rb, line 47
def self.create input
  case input
  when Gem::Requirement then
    input
  when Gem::Version, Array then
    new input
  else
    if input.respond_to? :to_str then
      new [input.to_str]
    else
      default
    end
  end
end
            
default() click to toggle source

A default “version requirement” can surely only be '>= 0'.

 
               # File rubygems/requirement.rb, line 65
def self.default
  new '>= 0'
end
            
new(*requirements) click to toggle source

Constructs a requirement from requirements. Requirements can be Strings, Gem::Versions, or Arrays of those. nil and duplicate requirements are ignored. An empty set of requirements is the same as ">= 0".

 
               # File rubygems/requirement.rb, line 112
def initialize *requirements
  requirements = requirements.flatten
  requirements.compact!
  requirements.uniq!

  if requirements.empty?
    @requirements = [DefaultRequirement]
  else
    @requirements = requirements.map! { |r| self.class.parse r }
  end
end
            
parse(obj) click to toggle source

REFACTOR: Little two element arrays like this have no real semantic value. I'd love to see something like this: Constraint = Struct.new(:operator, :version); (or similar) and have a Requirement be a list of Constraints.

 
               # File rubygems/requirement.rb, line 86
def self.parse obj
  return ["=", obj] if Gem::Version === obj

  unless PATTERN =~ obj.to_s
    raise BadRequirementError, "Illformed requirement [#{obj.inspect}]"
  end

  if $1 == ">=" && $2 == "0"
    DefaultRequirement
  else
    [$1 || "=", Gem::Version.new($2)]
  end
end
            

Public Instance Methods

==(other) click to toggle source

DOC: this should probably be :nodoc'd

 
               # File rubygems/requirement.rb, line 218
def == other
  Gem::Requirement === other and to_s == other.to_s
end
            
===(version) click to toggle source
Alias for: satisfied_by?
=~(version) click to toggle source
Alias for: satisfied_by?
encode_with(coder) click to toggle source
 
               # File rubygems/requirement.rb, line 173
def encode_with(coder)
  coder.add 'requirements', @requirements
end
            
none?() click to toggle source

FIX: maybe this should be using default ?

 
               # File rubygems/requirement.rb, line 128
def none?
  if @requirements.size == 1
    @requirements[0] == DefaultRequirement
  else
    false
  end
end
            
prerelease?() click to toggle source

A requirement is a prerelease if any of the versions inside of it are prereleases

 
               # File rubygems/requirement.rb, line 181
def prerelease?
  requirements.any? { |r| r.last.prerelease? }
end
            
satisfied_by?(version) click to toggle source

True if version satisfies this Requirement.

 
               # File rubygems/requirement.rb, line 194
def satisfied_by? version
  raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless
    Gem::Version === version
  # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
  requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
end
            
Also aliased as: ===, =~
specific?() click to toggle source

True if the requirement will not always match the latest version.

 
               # File rubygems/requirement.rb, line 207
def specific?
  return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly

  not %w[> >=].include? @requirements.first.first # grab the operator
end
            
to_yaml_properties() click to toggle source
 
               # File rubygems/requirement.rb, line 169
def to_yaml_properties
  ["@requirements"]
end