Class: DependencyGrapher::Analyzer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependencies = nil) ⇒ Analyzer

Returns a new instance of Analyzer.



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

def initialize(dependencies = nil)
  @dependencies = dependencies
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



5
6
7
# File 'lib/dependency_grapher/analyzer.rb', line 5

def dependencies
  @dependencies
end

Instance Method Details

#load_dependencies(dependencies) ⇒ Object



11
12
13
# File 'lib/dependency_grapher/analyzer.rb', line 11

def load_dependencies(dependencies)
  @dependencies = dependencies
end

#set_dependency_flagsObject



15
16
17
18
19
20
21
# File 'lib/dependency_grapher/analyzer.rb', line 15

def set_dependency_flags
  @dependencies.each do |dep|
    if dep.receiver.types.include?(:framework)
      dep.flags << :violation unless dep.kaller.types.include?(:service)
    end
  end
end

#set_method_typesObject

OPTIMIZE



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dependency_grapher/analyzer.rb', line 24

def set_method_types
  services = GetKnownClasses.call(:services)
  framework_roots = Set.new
  # Marks all receiver of service objects as :framework
  @dependencies.each do |dep|
    if services.include?(dep.kaller.root)
      dep.kaller.types << :service
      dep.receiver.types << :framework
      framework_roots << dep.receiver.root
    end
  end
  
  # Marks all methods with a root that is shared with 
  # methods in the frameworks list as :framework
  @dependencies.each do |dep|
    if framework_roots.include?(dep.kaller.root)
      dep.kaller.types << :framework
    elsif framework_roots.include?(dep.receiver.root)
      dep.receiver.types << :framework
    end
  end
end