Class: Librarian::Dependency::Requirement

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/dependency.rb

Constant Summary collapse

COMPATS_TABLE =
{
  %w(=  = ) => lambda{|s, o| s == o},
  %w(=  !=) => lambda{|s, o| s != o},
  %w(=  > ) => lambda{|s, o| s >  o},
  %w(=  < ) => lambda{|s, o| s <  o},
  %w(=  >=) => lambda{|s, o| s >= o},
  %w(=  <=) => lambda{|s, o| s <= o},
  %w(=  ~>) => lambda{|s, o| s >= o && s.release < o.bump},
  %w(!= !=) => true,
  %w(!= > ) => true,
  %w(!= < ) => true,
  %w(!= >=) => true,
  %w(!= <=) => true,
  %w(!= ~>) => true,
  %w(>  > ) => true,
  %w(>  < ) => lambda{|s, o| s < o},
  %w(>  >=) => true,
  %w(>  <=) => lambda{|s, o| s < o},
  %w(>  ~>) => lambda{|s, o| s < o.bump},
  %w(<  < ) => true,
  %w(<  >=) => lambda{|s, o| s > o},
  %w(<  <=) => true,
  %w(<  ~>) => lambda{|s, o| s > o},
  %w(>= >=) => true,
  %w(>= <=) => lambda{|s, o| s <= o},
  %w(>= ~>) => lambda{|s, o| s < o.bump},
  %w(<= <=) => true,
  %w(<= ~>) => lambda{|s, o| s >= o},
  %w(~> ~>) => lambda{|s, o| s < o.bump && s.bump > o},
}

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Requirement

Returns a new instance of Requirement.



7
8
9
10
11
# File 'lib/librarian/dependency.rb', line 7

def initialize(*args)
  args = initialize_normalize_args(args)

  self.backing = Gem::Requirement.create(*args)
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/librarian/dependency.rb', line 21

def ==(other)
  to_gem_requirement == other.to_gem_requirement
end

#consistent_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
# File 'lib/librarian/dependency.rb', line 64

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

#inconsistent_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/librarian/dependency.rb', line 74

def inconsistent_with?(other)
  !consistent_with?(other)
end

#inspectObject



29
30
31
# File 'lib/librarian/dependency.rb', line 29

def inspect
  "#<#{self.class} #{to_s}>"
end

#satisfied_by?(version) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/librarian/dependency.rb', line 17

def satisfied_by?(version)
  to_gem_requirement.satisfied_by?(version.to_gem_version)
end

#to_gem_requirementObject



13
14
15
# File 'lib/librarian/dependency.rb', line 13

def to_gem_requirement
  backing
end

#to_sObject



25
26
27
# File 'lib/librarian/dependency.rb', line 25

def to_s
  to_gem_requirement.to_s
end