solve 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -1
- data/README.md +1 -0
- data/lib/solve.rb +9 -12
- data/lib/solve/artifact.rb +0 -1
- data/lib/solve/constraint.rb +0 -2
- data/lib/solve/demand.rb +0 -1
- data/lib/solve/dependency.rb +0 -1
- data/lib/solve/errors.rb +0 -1
- data/lib/solve/gem_version.rb +1 -1
- data/lib/solve/graph.rb +0 -1
- data/lib/solve/solver.rb +10 -12
- data/lib/solve/solver/constraint_row.rb +2 -2
- data/lib/solve/solver/constraint_table.rb +0 -2
- data/lib/solve/solver/serializer.rb +8 -6
- data/lib/solve/solver/variable_row.rb +0 -2
- data/lib/solve/solver/variable_table.rb +0 -2
- data/lib/solve/version.rb +0 -2
- data/solve.gemspec +0 -2
- data/spec/acceptance/solutions_spec.rb +7 -7
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/solve/demand_spec.rb +1 -1
- data/spec/unit/solve/solver/serializer_spec.rb +1 -1
- data/spec/unit/solve_spec.rb +1 -1
- metadata +4 -20
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.3-
|
1
|
+
1.9.3-p429
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Solve
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/solve.png)](http://badge.fury.io/rb/solve)
|
2
3
|
[![Build Status](https://secure.travis-ci.org/reset/solve.png?branch=master)](http://travis-ci.org/reset/solve)
|
3
4
|
[![Dependency Status](https://gemnasium.com/reset/solve.png?travis)](https://gemnasium.com/reset/solve)
|
4
5
|
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/reset/solve)
|
data/lib/solve.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
require 'json'
|
3
|
-
require 'solve/errors'
|
4
|
-
|
5
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
6
1
|
module Solve
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
require_relative 'solve/artifact'
|
3
|
+
require_relative 'solve/constraint'
|
4
|
+
require_relative 'solve/demand'
|
5
|
+
require_relative 'solve/dependency'
|
6
|
+
require_relative 'solve/gem_version'
|
7
|
+
require_relative 'solve/errors'
|
8
|
+
require_relative 'solve/graph'
|
9
|
+
require_relative 'solve/solver'
|
10
|
+
require_relative 'solve/version'
|
14
11
|
|
15
12
|
class << self
|
16
13
|
# A quick solve. Given the "world" as we know it (the graph) and a list of
|
data/lib/solve/artifact.rb
CHANGED
data/lib/solve/constraint.rb
CHANGED
data/lib/solve/demand.rb
CHANGED
data/lib/solve/dependency.rb
CHANGED
data/lib/solve/errors.rb
CHANGED
data/lib/solve/gem_version.rb
CHANGED
data/lib/solve/graph.rb
CHANGED
data/lib/solve/solver.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
+
require_relative 'solver/variable_table'
|
2
|
+
require_relative 'solver/variable_row'
|
3
|
+
require_relative 'solver/constraint_table'
|
4
|
+
require_relative 'solver/constraint_row'
|
5
|
+
require_relative 'solver/serializer'
|
6
|
+
|
1
7
|
module Solve
|
2
|
-
# @author Jamie Winsor <reset@riotgames.com>
|
3
|
-
# @author Andrew Garson <agarson@riotgames.com>
|
4
8
|
class Solver
|
5
|
-
autoload :VariableTable, 'solve/solver/variable_table'
|
6
|
-
autoload :VariableRow, 'solve/solver/variable_row'
|
7
|
-
autoload :ConstraintTable, 'solve/solver/constraint_table'
|
8
|
-
autoload :ConstraintRow, 'solve/solver/constraint_row'
|
9
|
-
autoload :Serializer, 'solve/solver/serializer'
|
10
|
-
|
11
9
|
class << self
|
12
10
|
# Create a key to identify a demand on a Solver.
|
13
11
|
#
|
@@ -74,7 +72,7 @@ module Solve
|
|
74
72
|
# @param [Solve::Graph] graph
|
75
73
|
# @param [Array<String>, Array<Array<String, String>>] demands
|
76
74
|
# @param [#say] ui
|
77
|
-
def initialize(graph, demands = Array.new, ui=nil)
|
75
|
+
def initialize(graph, demands = Array.new, ui=nil)
|
78
76
|
@graph = graph
|
79
77
|
@demands = Hash.new
|
80
78
|
@ui = ui.respond_to?(:say) ? ui : nil
|
@@ -109,7 +107,7 @@ module Solve
|
|
109
107
|
all_ok = possible_dependencies.all? { |dependency| can_add_new_constraint?(dependency) }
|
110
108
|
if all_ok
|
111
109
|
trace("Attempting to use #{possible_artifact}")
|
112
|
-
add_dependencies(possible_dependencies, possible_artifact)
|
110
|
+
add_dependencies(possible_dependencies, possible_artifact)
|
113
111
|
unbound_variable.bind(possible_value)
|
114
112
|
break
|
115
113
|
end
|
@@ -117,7 +115,7 @@ module Solve
|
|
117
115
|
|
118
116
|
unless unbound_variable.bound?
|
119
117
|
trace("Could not find an acceptable value for #{unbound_variable.artifact}")
|
120
|
-
backtrack(unbound_variable)
|
118
|
+
backtrack(unbound_variable)
|
121
119
|
end
|
122
120
|
end
|
123
121
|
|
@@ -284,7 +282,7 @@ module Solve
|
|
284
282
|
trace("Removed constraint #{removed_constraint.name} #{removed_constraint.constraint}")
|
285
283
|
end
|
286
284
|
previous_variable.unbind
|
287
|
-
variable_table.all_after(previous_variable.artifact).each do |variable|
|
285
|
+
variable_table.all_after(previous_variable.artifact).each do |variable|
|
288
286
|
new_possibles = reset_possible_values_for(variable)
|
289
287
|
end
|
290
288
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Solve
|
2
4
|
class Solver
|
3
5
|
class Serializer
|
@@ -46,7 +48,7 @@ module Solve
|
|
46
48
|
list << format_dependency(dependency)
|
47
49
|
end
|
48
50
|
|
49
|
-
{
|
51
|
+
{
|
50
52
|
"name" => artifact.name,
|
51
53
|
"version" => artifact.version.to_s,
|
52
54
|
"dependencies" => dependencies
|
@@ -54,21 +56,21 @@ module Solve
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def format_dependency(dependency)
|
57
|
-
{
|
58
|
-
"name" => dependency.name,
|
59
|
+
{
|
60
|
+
"name" => dependency.name,
|
59
61
|
"constraint" => dependency.constraint.to_s
|
60
62
|
}
|
61
63
|
end
|
62
64
|
|
63
65
|
def format_demands(demands)
|
64
|
-
demands_list = demands.inject([]) do |list, demand|
|
65
|
-
list << format_demand(demand)
|
66
|
+
demands_list = demands.inject([]) do |list, demand|
|
67
|
+
list << format_demand(demand)
|
66
68
|
end
|
67
69
|
{ "demands" => demands_list }
|
68
70
|
end
|
69
71
|
|
70
72
|
def format_demand(demand)
|
71
|
-
{
|
73
|
+
{
|
72
74
|
"name" => demand.name,
|
73
75
|
"constraint" => demand.constraint.to_s
|
74
76
|
}
|
data/lib/solve/version.rb
CHANGED
data/solve.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Solutions" do
|
4
|
-
|
4
|
+
|
5
5
|
it "chooses the correct artifact for the demands" do
|
6
6
|
graph = Solve::Graph.new
|
7
7
|
graph.artifacts("mysql", "2.0.0")
|
@@ -18,13 +18,13 @@ describe "Solutions" do
|
|
18
18
|
graph.artifacts("mysql", "2.0.0")
|
19
19
|
graph.artifacts("mysql", "1.2.0")
|
20
20
|
graph.artifacts("nginx", "1.0.0").depends("mysql", ">= 1.2.0")
|
21
|
-
|
21
|
+
|
22
22
|
result = Solve.it!(graph, [['nginx', '= 1.0.0'], ['mysql']])
|
23
23
|
|
24
24
|
result.should eql("nginx" => "1.0.0", "mysql" => "2.0.0")
|
25
25
|
end
|
26
26
|
|
27
|
-
it "raises NoSolutionError when a solution cannot be found" do
|
27
|
+
it "raises NoSolutionError when a solution cannot be found" do
|
28
28
|
graph = Solve::Graph.new
|
29
29
|
graph.artifacts("mysql", "1.2.0")
|
30
30
|
|
@@ -76,7 +76,7 @@ describe "Solutions" do
|
|
76
76
|
|
77
77
|
result = Solve.it!(graph, [["A", "1.0.0"]])
|
78
78
|
|
79
|
-
result.should eql("A" => "1.0.0",
|
79
|
+
result.should eql("A" => "1.0.0",
|
80
80
|
"B" => "1.0.0",
|
81
81
|
"C" => "1.0.0")
|
82
82
|
end
|
@@ -90,7 +90,7 @@ describe "Solutions" do
|
|
90
90
|
|
91
91
|
result = Solve.it!(graph, [["A", "1.0.0"]])
|
92
92
|
|
93
|
-
result.should eql("A" => "1.0.0",
|
93
|
+
result.should eql("A" => "1.0.0",
|
94
94
|
"B" => "1.0.0",
|
95
95
|
"C" => "1.0.0")
|
96
96
|
end
|
@@ -141,7 +141,7 @@ describe "Solutions" do
|
|
141
141
|
graph.artifacts("D", "1.0.0").depends("A", "< 0.0.0")
|
142
142
|
|
143
143
|
# Add a solution to the graph that should be reached only after
|
144
|
-
# all of the others have been tried
|
144
|
+
# all of the others have been tried
|
145
145
|
# it must be circular to ensure that no other branch can find it
|
146
146
|
graph.artifacts("A", "0.0.0").depends("B", "0.0.0")
|
147
147
|
graph.artifacts("B", "0.0.0").depends("C", "0.0.0")
|
@@ -151,7 +151,7 @@ describe "Solutions" do
|
|
151
151
|
demands = [["A"]]
|
152
152
|
|
153
153
|
result = Solve.it!(graph, demands)
|
154
|
-
|
154
|
+
|
155
155
|
result.should eql({ "A" => "0.0.0",
|
156
156
|
"B" => "0.0.0",
|
157
157
|
"C" => "0.0.0",
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/solve_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,24 +11,8 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: json
|
18
|
-
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
|
-
requirements:
|
21
|
-
- - ! '>='
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: '0'
|
24
|
-
type: :runtime
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
|
-
requirements:
|
29
|
-
- - ! '>='
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: '0'
|
14
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
15
|
+
dependencies: []
|
32
16
|
description: A Ruby version constraint solver
|
33
17
|
email:
|
34
18
|
- reset@riotgames.com
|
@@ -94,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
78
|
version: '0'
|
95
79
|
segments:
|
96
80
|
- 0
|
97
|
-
hash:
|
81
|
+
hash: 2797902556656574855
|
98
82
|
requirements: []
|
99
83
|
rubyforge_project:
|
100
84
|
rubygems_version: 1.8.23
|