Class: DependencyGrapher::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/dependency_grapher/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilter

Returns a new instance of Filter.



7
8
9
# File 'lib/dependency_grapher/filter.rb', line 7

def initialize
  @dependencies = nil
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



6
7
8
# File 'lib/dependency_grapher/filter.rb', line 6

def dependencies
  @dependencies
end

Instance Method Details

#filterObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dependency_grapher/filter.rb', line 11

def filter
  tmp_deps = Set.new
  receiver = {}

  # Crawl ActiveSupport::Dependencies.autoload_paths for known classes
  known_classes = GetKnownClasses.call

  @dependencies.each_with_index do |dep, i|
    kaller = dep.kaller
    receiver = dep.receiver
    # all pass_conds must be true for dependency to be added to calculated_dependencies
    pass_conds = true
    pass_conds &&= kaller.id != receiver.id
    pass_conds &&= (known_classes.include?(kaller.root) || known_classes.include?(receiver.root))
    tmp_deps << dep if pass_conds
  end

  @dependencies = tmp_deps
end

#load_dependencies(dependencies) ⇒ Object



35
36
37
# File 'lib/dependency_grapher/filter.rb', line 35

def load_dependencies(dependencies)
  @dependencies = dependencies
end

#load_file(filename = "dependencies.yml") ⇒ Object



31
32
33
# File 'lib/dependency_grapher/filter.rb', line 31

def load_file(filename = "dependencies.yml")
  @dependencies = DeserializeDependencies.call(filename)
end