Class: Bundler::PubGrub::VersionSolver

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, root: Package.root, logger: Bundler::PubGrub.logger) ⇒ VersionSolver

Returns a new instance of VersionSolver.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 12

def initialize(source:, root: Package.root, logger: Bundler::PubGrub.logger)
  @logger = logger

  @source = source

  # { package => [incompatibility, ...]}
  @incompatibilities = Hash.new do |h, k|
    h[k] = []
  end

  @seen_incompatibilities = {}

  @solution = PartialSolution.new

  add_incompatibility Incompatibility.new([
    Term.new(VersionConstraint.any(root), false)
  ], cause: :root)

  propagate(root)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 8

def logger
  @logger
end

#solutionObject (readonly)

Returns the value of attribute solution.



10
11
12
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 10

def solution
  @solution
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 9

def source
  @source
end

Instance Method Details

#solveObject Also known as: result



57
58
59
60
61
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 57

def solve
  work until solved?

  solution.decisions
end

#solved?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 33

def solved?
  solution.unsatisfied.empty?
end

#workObject

Returns true if there is more work to be done, false otherwise



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 38

def work
  return false if solved?

  next_package = choose_package_version
  propagate(next_package)

  if solved?
    logger.info { "Solution found after #{solution.attempted_solutions} attempts:" }
    solution.decisions.each do |package, version|
      next if Package.root?(package)
      logger.info { "* #{package} #{version}" }
    end

    false
  else
    true
  end
end