Class: MOSAIK::Extractors::Structural

Inherits:
MOSAIK::Extractor show all
Defined in:
lib/mosaik/extractors/structural.rb,
lib/mosaik/extractors/structural/parser.rb,
lib/mosaik/extractors/structural/processor.rb

Overview

Structural coupling extractor

Defined Under Namespace

Classes: Parser, Processor

Instance Attribute Summary

Attributes inherited from MOSAIK::Extractor

#graph, #options

Instance Method Summary collapse

Methods inherited from MOSAIK::Extractor

#initialize, #validate

Constructor Details

This class inherits a constructor from MOSAIK::Extractor

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mosaik/extractors/structural.rb', line 9

def call
  # Instantiate a constant tree
  tree = Syntax::Tree.new

  # Parse files
  MOSAIK.configuration.files.each do |file|
    Parser
      .new
      .parse(file, tree)
  end

  # Count total constants and methods
  total = tree.to_h { |c| [c.name, c.methods.size] }
  info "Parsed #{total.size} classes and #{total.values.sum} methods"

  # Print the constant tree
  tree.each do |constant|
    debug constant

    constant.methods.each_value do |method|
      debug "  #{method}"

      method.references.each do |reference|
        debug "    #{reference}"
      end
    end

    # Print the hierarchy
    debug ("  " * constant.name.scan("::").size) + constant.name
  end

  # Construct the graph
  tree.each { |constant| construct(constant) } # rubocop:disable Style/CombinableLoops
end