Class: Solve::RubySolver
- Inherits:
-
Object
- Object
- Solve::RubySolver
- Defined in:
- lib/solve/ruby_solver.rb
Instance Attribute Summary collapse
-
#demands_array ⇒ Array<String>, Array<Array<String, String>>
readonly
Demands.
-
#graph ⇒ Solve::Graph
readonly
Graph object with references to all known artifacts and dependency constraints.
Class Method Summary collapse
-
.activate ⇒ Object
For optinal solver engines, this attempts to load depenencies.
-
.timeout ⇒ Integer
The timeout (in seconds) to use when resolving graphs.
Instance Method Summary collapse
-
#after_resolution ⇒ Object
Callback required by Molinillo, called when the solve is complete.
-
#before_resolution ⇒ Object
Callback required by Molinillo, called when the solve starts.
-
#debug(current_resolver_depth) ⇒ Object
Callback required by Molinillo, gives debug information about the solution.
-
#demands ⇒ Array<Solve::Demand>
The problem demands given as Demand model objects.
-
#dependencies_for(specification) ⇒ Array<Solve::Dependency>
Callback required by Molinillo.
-
#initialize(graph, demands, options = {}) ⇒ RubySolver
constructor
A new instance of RubySolver.
-
#name_for(dependency) ⇒ String
Callback required by Molinillo.
-
#name_for_explicit_dependency_source ⇒ String
The name of the source of explicit dependencies, i.e.
-
#name_for_locking_dependency_source ⇒ String
The name of the source of ‘locked’ dependencies, i.e.
-
#progress_rate ⇒ Integer
Callback required by Molinillo, called when the solve starts.
-
#requirement_satisfied_by?(requirement, activated, spec) ⇒ Boolean
Callback required by Molinillo.
-
#resolve(options = {}) ⇒ Hash, List
Returns a hash like { “Artifact Name” => “Version”,… } unless the :sorted option is true, then it returns a list like [[“Artifact Name”, “Version],…].
-
#search_for(dependency) ⇒ Array<Solve::Artifact>
Callback required by Molinillo.
-
#sort_dependencies(dependencies, activated, conflicts) ⇒ Array<Solve::Dependency>
Callback required by Molinillo.
Constructor Details
#initialize(graph, demands, options = {}) ⇒ RubySolver
Returns a new instance of RubySolver.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/solve/ruby_solver.rb', line 42 def initialize(graph, demands, = {}) @graph = graph @demands_array = demands @timeout_ms = self.class.timeout @dependency_source = [:dependency_source] || 'user-specified dependency' @molinillo_graph = Molinillo::DependencyGraph.new @resolver = Molinillo::Resolver.new(self, self) end |
Instance Attribute Details
#demands_array ⇒ Array<String>, Array<Array<String, String>> (readonly)
Returns demands.
33 34 35 |
# File 'lib/solve/ruby_solver.rb', line 33 def demands_array @demands_array end |
#graph ⇒ Solve::Graph (readonly)
Graph object with references to all known artifacts and dependency constraints.
28 29 30 |
# File 'lib/solve/ruby_solver.rb', line 28 def graph @graph end |
Class Method Details
.activate ⇒ Object
For optinal solver engines, this attempts to load depenencies. The RubySolver is a non-optional component, so this is a no-op
19 20 21 |
# File 'lib/solve/ruby_solver.rb', line 19 def activate true end |
.timeout ⇒ Integer
The timeout (in seconds) to use when resolving graphs. Default is 10. This can be configured by setting the SOLVE_TIMEOUT environment variable.
12 13 14 15 |
# File 'lib/solve/ruby_solver.rb', line 12 def timeout seconds = 30 unless seconds = ENV["SOLVE_TIMEOUT"] seconds.to_i * 1_000 end |
Instance Method Details
#after_resolution ⇒ Object
Callback required by Molinillo, called when the solve is complete.
111 112 113 |
# File 'lib/solve/ruby_solver.rb', line 111 def after_resolution nil end |
#before_resolution ⇒ Object
Callback required by Molinillo, called when the solve starts
105 106 107 |
# File 'lib/solve/ruby_solver.rb', line 105 def before_resolution nil end |
#debug(current_resolver_depth) ⇒ Object
Callback required by Molinillo, gives debug information about the solution
117 118 119 120 121 |
# File 'lib/solve/ruby_solver.rb', line 117 def debug(current_resolver_depth) # debug info will be returned if you call yield here, but it seems to be # broken in current Molinillo nil end |
#demands ⇒ Array<Solve::Demand>
The problem demands given as Demand model objects
55 56 57 58 59 |
# File 'lib/solve/ruby_solver.rb', line 55 def demands demands_array.map do |name, constraint| Demand.new(self, name, constraint) end end |
#dependencies_for(specification) ⇒ Array<Solve::Dependency>
Callback required by Molinillo
158 159 160 |
# File 'lib/solve/ruby_solver.rb', line 158 def dependencies_for(specification) specification.dependencies end |
#name_for(dependency) ⇒ String
Callback required by Molinillo
125 126 127 |
# File 'lib/solve/ruby_solver.rb', line 125 def name_for(dependency) dependency.name end |
#name_for_explicit_dependency_source ⇒ String
Returns the name of the source of explicit dependencies, i.e. those passed to Resolver#resolve directly.
164 165 166 |
# File 'lib/solve/ruby_solver.rb', line 164 def name_for_explicit_dependency_source @dependency_source end |
#name_for_locking_dependency_source ⇒ String
Returns the name of the source of ‘locked’ dependencies, i.e. those passed to Resolver#resolve directly as the ‘base`.
170 171 172 |
# File 'lib/solve/ruby_solver.rb', line 170 def name_for_locking_dependency_source 'Lockfile' end |
#progress_rate ⇒ Integer
Callback required by Molinillo, called when the solve starts
99 100 101 |
# File 'lib/solve/ruby_solver.rb', line 99 def progress_rate 1 end |
#requirement_satisfied_by?(requirement, activated, spec) ⇒ Boolean
Callback required by Molinillo
152 153 154 |
# File 'lib/solve/ruby_solver.rb', line 152 def requirement_satisfied_by?(requirement, activated, spec) requirement.constraint.satisfies?(spec.version) end |
#resolve(options = {}) ⇒ Hash, List
Returns a hash like { “Artifact Name” => “Version”,… } unless the :sorted option is true, then it returns a list like [[“Artifact Name”, “Version],…]
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/solve/ruby_solver.rb', line 71 def resolve( = {}) solved_graph = resolve_with_error_wrapping solution = solved_graph.map(&:payload) unsorted_solution = solution.inject({}) do |stringified_soln, artifact| stringified_soln[artifact.name] = artifact.version.to_s stringified_soln end if [:sorted] build_sorted_solution(unsorted_solution) else unsorted_solution end end |
#search_for(dependency) ⇒ Array<Solve::Artifact>
Callback required by Molinillo
144 145 146 147 148 |
# File 'lib/solve/ruby_solver.rb', line 144 def search_for(dependency) # This array gets mutated by Molinillo; it's okay because sort returns a # new array. graph.versions(dependency.name, dependency.constraint).sort end |
#sort_dependencies(dependencies, activated, conflicts) ⇒ Array<Solve::Dependency>
Callback required by Molinillo
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/solve/ruby_solver.rb', line 131 def sort_dependencies(dependencies, activated, conflicts) dependencies.sort_by do |dependency| name = name_for(dependency) [ activated.vertex_named(name).payload ? 0 : 1, conflicts[name] ? 0 : 1, activated.vertex_named(name).payload ? 0 : graph.versions(dependency.name).count, ] end end |