Class: Bundler::PubGrub::VersionSolver
- Inherits:
-
Object
- Object
- Bundler::PubGrub::VersionSolver
- Defined in:
- lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#solution ⇒ Object
readonly
Returns the value of attribute solution.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#initialize(source:, root: Package.root, strategy: Strategy.new(source), logger: Bundler::PubGrub.logger) ⇒ VersionSolver
constructor
A new instance of VersionSolver.
- #solve ⇒ Object (also: #result)
- #solved? ⇒ Boolean
-
#work ⇒ Object
Returns true if there is more work to be done, false otherwise.
Constructor Details
#initialize(source:, root: Package.root, strategy: Strategy.new(source), logger: Bundler::PubGrub.logger) ⇒ VersionSolver
Returns a new instance of VersionSolver.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 14 def initialize(source:, root: Package.root, strategy: Strategy.new(source), logger: Bundler::PubGrub.logger) @logger = logger @source = source @strategy = strategy # { 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
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 9 def logger @logger end |
#solution ⇒ Object (readonly)
Returns the value of attribute solution.
11 12 13 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 11 def solution @solution end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 10 def source @source end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
12 13 14 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 12 def strategy @strategy end |
Instance Method Details
#solve ⇒ Object Also known as: result
59 60 61 62 63 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 59 def solve while work; end solution.decisions end |
#solved? ⇒ Boolean
36 37 38 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 36 def solved? solution.unsatisfied.empty? end |
#work ⇒ Object
Returns true if there is more work to be done, false otherwise
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb', line 41 def work unsatisfied_terms = solution.unsatisfied if unsatisfied_terms.empty? 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 return false end next_package = choose_package_version_from(unsatisfied_terms) propagate(next_package) true end |