Class: Doubleshot::Resolver::GemResolver::Solver::VariableTable

Inherits:
Object
  • Object
show all
Defined in:
lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVariableTable

Returns a new instance of VariableTable.



8
9
10
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 8

def initialize
  @rows = Array.new
end

Instance Attribute Details

#rowsObject (readonly)

Returns the value of attribute rows.



6
7
8
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 6

def rows
  @rows
end

Instance Method Details

#add(artifact, source) ⇒ Object

Parameters:



14
15
16
17
18
19
20
21
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 14

def add(artifact, source)
  row = rows.detect { |row| row.artifact == artifact }
  if row.nil?
    @rows << VariableRow.new(artifact, source)
  else
    row.add_source(source)
  end
end

#all_after(artifact) ⇒ Object

Parameters:



51
52
53
54
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 51

def all_after(artifact)
  artifact_index = @rows.index { |row| row.artifact == artifact }
  @rows[(artifact_index+1)..-1]
end

#all_from_source(source) ⇒ Object

Parameters:



40
41
42
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 40

def all_from_source(source)
  @rows.select { |row| row.sources.include?(source) }
end

#before(artifact) ⇒ Object

Parameters:



45
46
47
48
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 45

def before(artifact)
  artifact_index = @rows.index { |row| row.artifact == artifact }
  (artifact_index == 0) ? nil : @rows[artifact_index - 1]
end

#find_artifact(artifact) ⇒ Object

Parameters:



28
29
30
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 28

def find_artifact(artifact)
  @rows.detect { |row| row.artifact == artifact }
end

#first_unboundObject



23
24
25
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 23

def first_unbound
  @rows.detect { |row| row.bound? == false }
end

#remove_all_with_only_this_source!(source) ⇒ Object

Parameters:



33
34
35
36
37
# File 'lib/doubleshot/resolver/gem_resolver/solver/variable_table.rb', line 33

def remove_all_with_only_this_source!(source)
  with_only_this_source, others = @rows.partition { |row| row.sources == [source] }
  @rows = others
  with_only_this_source
end