class Buildr::VersionRequirement

See Buildr::ArtifactNamespace#need

See Buildr::ArtifactNamespace#need

Constants

BOOL_CHARS
CMP_CHARS
CMP_PROCS
CMP_REGEX
VER_CHARS

Attributes

negative[RW]
op[R]
requirements[R]

Public Class Methods

create(" >1 <2 !(1.5) ") → requirement click to toggle source

parse the str requirement

# File lib/buildr/java/version_requirement.rb, line 44
def create(str)
  instance_eval normalize(str)
rescue StandardError => e
  raise "Failed to parse #{str.inspect} due to: #{e}"
end
requirement?(str) click to toggle source

is str a version requirement?

# File lib/buildr/java/version_requirement.rb, line 36
def requirement?(str)
  /[#{BOOL_CHARS}#{CMP_CHARS}\(\)]/ === str
end
version?(str) click to toggle source

is str a version string?

# File lib/buildr/java/version_requirement.rb, line 31
def version?(str)
  /^\s*[#{VER_CHARS}]+\s*$/ === str
end

Public Instance Methods

&(other) click to toggle source

Either modify the current requirement (if it’s already an and operation) or create a new requirement

# File lib/buildr/java/version_requirement.rb, line 147
def &(other)
  operation(:&, other)
end
composed?() click to toggle source

Is this object a composed requirement?

VersionRequirement.create('1').composed? -> false
VersionRequirement.create('1 | 2').composed? -> true
VersionRequirement.create('1 & 2').composed? -> true
# File lib/buildr/java/version_requirement.rb, line 101
def composed?
  requirements.size > 1
end
default() click to toggle source

Return the last requirement on this object having an = operator.

# File lib/buildr/java/version_requirement.rb, line 106
def default
  default = nil
  requirements.reverse.find do |r|
    if Array === r
      if !negative && (r.first.nil? || r.first.include?('='))
        default = r.last.to_s
      end
    else
      default = r.default
    end
  end
  default
end
satisfied_by?(version) click to toggle source

Test if this requirement can be satisfied by version

# File lib/buildr/java/version_requirement.rb, line 121
def satisfied_by?(version)
  return false unless version
  unless version.kind_of?(Gem::Version)
    raise "Invalid version: #{version.inspect}" unless self.class.version?(version)
    version = Gem::Version.new(0).tap { |v| v.version = version.strip }
  end
  message = op == :|  :any? : :all?
  result = requirements.send message do |req|
    if Array === req
      cmp, rv = *req
      CMP_PROCS[cmp || '='].call(version, rv)
    else
      req.satisfied_by?(version)
    end
  end
  negative ? !result : result
end
to_s() click to toggle source

return the parsed expression

# File lib/buildr/java/version_requirement.rb, line 152
def to_s
  str = requirements.map(&:to_s).join(" " + @op.to_s + " ").to_s
  str = "( " + str + " )" if negative || requirements.size > 1
  str = "!" + str if negative
  str
end
|(other) click to toggle source

Either modify the current requirement (if it’s already an or operation) or create a new requirement

# File lib/buildr/java/version_requirement.rb, line 141
def |(other)
  operation(:|, other)
end

Protected Instance Methods

operation(op, other) click to toggle source
# File lib/buildr/java/version_requirement.rb, line 162
def operation(op, other)
  @op ||= op
  if negative == other.negative && @op == op && other.requirements.size == 1
    @requirements << other.requirements.first
    self
  else
    self.class.new(op, self, other)
  end
end