class Librarian::Dependency::Requirement
Constants
- COMPATS_TABLE
Attributes
backing[RW]
Public Class Methods
new(*args)
click to toggle source
# File lib/librarian/dependency.rb, line 7 def initialize(*args) args = initialize_normalize_args(args) self.backing = Gem::Requirement.create(args) end
Public Instance Methods
==(other)
click to toggle source
# File lib/librarian/dependency.rb, line 21 def ==(other) to_gem_requirement == other.to_gem_requirement end
Also aliased as: eql?
consistent_with?(other)
click to toggle source
# File lib/librarian/dependency.rb, line 70 def consistent_with?(other) sgreq, ogreq = to_gem_requirement, other.to_gem_requirement sreqs, oreqs = sgreq.requirements, ogreq.requirements sreqs.all? do |sreq| oreqs.all? do |oreq| compatible?(sreq, oreq) end end end
hash()
click to toggle source
# File lib/librarian/dependency.rb, line 27 def hash self.to_s.hash end
inconsistent_with?(other)
click to toggle source
# File lib/librarian/dependency.rb, line 80 def inconsistent_with?(other) !consistent_with?(other) end
inspect()
click to toggle source
# File lib/librarian/dependency.rb, line 35 def inspect "#<#{self.class} #{to_s}>" end
satisfied_by?(version)
click to toggle source
# File lib/librarian/dependency.rb, line 17 def satisfied_by?(version) to_gem_requirement.satisfied_by?(version.to_gem_version) end
to_gem_requirement()
click to toggle source
# File lib/librarian/dependency.rb, line 13 def to_gem_requirement backing end
to_s()
click to toggle source
# File lib/librarian/dependency.rb, line 31 def to_s to_gem_requirement.to_s end
Private Instance Methods
compatible?(a, b)
click to toggle source
# File lib/librarian/dependency.rb, line 119 def compatible?(a, b) a, b = b, a unless COMPATS_TABLE.include?([a.first, b.first]) r = COMPATS_TABLE[[a.first, b.first]] r = r.call(a.last, b.last) if r.respond_to?(:call) r end
initialize_normalize_args(args)
click to toggle source
# File lib/librarian/dependency.rb, line 90 def initialize_normalize_args(args) args.map do |arg| arg = arg.backing if self.class === arg case arg when nil nil when Array arg.map { |item| parse(item) } when String parse(arg) else # Gem::Requirement, convert to string (ie. =1.0) so we can concat later # Gem::Requirements can not be concatenated arg.requirements.map{|x,y| "#{x}#{y}"} end end.flatten end
parse(arg)
click to toggle source
build an array if the argument is a string defining a range or a ~> 1.0 type version if string is 1.x
# File lib/librarian/dependency.rb, line 110 def parse(arg) return nil if arg.nil? match = range_requirement(arg) return [match[1], match[2]] if match match = pessimistic_requirement(arg) return "~> #{match[1]}.0" if match arg end
pessimistic_requirement(arg)
click to toggle source
A string with .x: 1.x, 2.1.x
# File lib/librarian/dependency.rb, line 132 def pessimistic_requirement(arg) arg.match(/(\d+(?:\.\d+)?)\.x/) end
range_requirement(arg)
click to toggle source
A version range: >=1.0 <2.0
# File lib/librarian/dependency.rb, line 127 def range_requirement(arg) arg.match(/(>=? ?\d+(?:\.\d+){0,2})\s*(<=? ?\d+(?:\.\d+){0,2})/) end