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 CHANGED
@@ -1 +1 @@
1
- 1.9.3-p392
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
- autoload :Version, 'solve/version'
8
- autoload :Artifact, 'solve/artifact'
9
- autoload :Constraint, 'solve/constraint'
10
- autoload :Dependency, 'solve/dependency'
11
- autoload :Graph, 'solve/graph'
12
- autoload :Demand, 'solve/demand'
13
- autoload :Solver, 'solve/solver'
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
@@ -1,5 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class Artifact
4
3
  include Comparable
5
4
 
@@ -1,6 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
- # @author Thibaud Guillaume-Gentil <thibaud@thibaud.me>
4
2
  class Constraint
5
3
  class << self
6
4
  # Split a constraint string into an Array of two elements. The first
data/lib/solve/demand.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class Demand
4
3
  # A reference to the solver this demand belongs to
5
4
  #
@@ -1,5 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class Dependency
4
3
  # A reference to the artifact this dependency belongs to
5
4
  #
data/lib/solve/errors.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  module Errors
4
3
  class SolveError < StandardError
5
4
  alias_method :mesage, :to_s
@@ -1,3 +1,3 @@
1
1
  module Solve
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/solve/graph.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class Graph
4
3
  class << self
5
4
  # Create a key for a graph from an instance of an Artifact or Dependency
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,7 +1,7 @@
1
+ require 'forwardable'
2
+
1
3
  module Solve
2
4
  class Solver
3
- # @author Andrew Garson <agarson@riotgames.com>
4
- # @author Jamie Winsor <reset@riotgames.com>
5
5
  class ConstraintRow
6
6
  extend Forwardable
7
7
 
@@ -1,7 +1,5 @@
1
1
  module Solve
2
2
  class Solver
3
- # @author Andrew Garson <agarson@riotgames.com>
4
- # @author Jamie Winsor <reset@riotgames.com>
5
3
  class ConstraintTable
6
4
  attr_reader :rows
7
5
 
@@ -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
  }
@@ -1,7 +1,5 @@
1
1
  module Solve
2
2
  class Solver
3
- # @author Andrew Garson <agarson@riotgames.com>
4
- # @author Jamie Winsor <reset@riotgames.com>
5
3
  class VariableRow
6
4
  attr_reader :artifact
7
5
  attr_reader :value
@@ -1,7 +1,5 @@
1
1
  module Solve
2
2
  class Solver
3
- # @author Andrew Garson <agarson@riotgames.com>
4
- # @author Jamie Winsor <reset@riotgames.com>
5
3
  class VariableTable
6
4
  attr_reader :rows
7
5
 
data/lib/solve/version.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  module Solve
2
- # @author Jamie Winsor <reset@riotgames.com>
3
- # @author Thibaud Guillaume-Gentil <thibaud@thibaud.me>
4
2
  class Version
5
3
  class << self
6
4
  # @param [#to_s] version_string
data/solve.gemspec CHANGED
@@ -16,6 +16,4 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
  s.version = Solve::VERSION
18
18
  s.required_ruby_version = ">= 1.9.1"
19
-
20
- s.add_dependency 'json'
21
19
  end
@@ -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
@@ -4,9 +4,9 @@ require 'spork'
4
4
 
5
5
  Spork.prefork do
6
6
  require 'rspec'
7
-
7
+
8
8
  APP_ROOT = File.expand_path('../../', __FILE__)
9
-
9
+
10
10
  Dir[File.join(APP_ROOT, "spec/support/**/*.rb")].each {|f| require f}
11
11
 
12
12
  RSpec.configure do |config|
@@ -80,7 +80,7 @@ describe Solve::Demand do
80
80
 
81
81
  subject.should_not eql(other)
82
82
  end
83
-
83
+
84
84
  it "returns false when other is a Solve::Demand with the same constraint but a different name" do
85
85
  other = Solve::Demand.new(solver, "chicken", constraint)
86
86
 
@@ -18,7 +18,7 @@ describe Solve::Solver::Serializer do
18
18
 
19
19
  solver.graph.should eql(deserialized.graph)
20
20
  solver.demands.should eql(deserialized.demands)
21
-
21
+
22
22
  result = solver.resolve
23
23
  deserialized_result = deserialized.resolve
24
24
  result.should eql(deserialized_result)
@@ -10,7 +10,7 @@ describe Solve do
10
10
  end
11
11
  end
12
12
 
13
- describe "#it!" do
13
+ describe "#it!" do
14
14
  it "raises NoSolutionError if a solution does not exist" do
15
15
  pending
16
16
  end
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.4
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-05-07 00:00:00.000000000 Z
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: -3360162225470919551
81
+ hash: 2797902556656574855
98
82
  requirements: []
99
83
  rubyforge_project:
100
84
  rubygems_version: 1.8.23