Class: FastCov::ConnectedDependencies

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_cov/connected_dependencies.rb

Instance Method Summary collapse

Constructor Details

#initializeConnectedDependencies

Returns a new instance of ConnectedDependencies.



5
6
7
8
# File 'lib/fast_cov/connected_dependencies.rb', line 5

def initialize
  @connections = {}
  @mutex = Mutex.new
end

Instance Method Details

#connect(from:, to:) ⇒ Object



10
11
12
13
14
# File 'lib/fast_cov/connected_dependencies.rb', line 10

def connect(from:, to:)
  @mutex.synchronize do
    (@connections[from] ||= {})[to] = true
  end
end

#expand(paths) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fast_cov/connected_dependencies.rb', line 16

def expand(paths)
  raise ArgumentError, "paths must be a Set" unless paths.is_a?(Set)

  pending_paths = paths.to_a

  until pending_paths.empty?
    path = pending_paths.pop

    connections = @connections[path]
    next unless connections

    connections.each_key do |dependency|
      next unless paths.add?(dependency)

      pending_paths << dependency
    end
  end

  paths
end