Class: MOSAIK::Commands::Extract

Inherits:
MOSAIK::Command::Graph show all
Defined in:
lib/mosaik/commands/extract.rb

Overview

Extract information from the application

Instance Method Summary collapse

Instance Method Details

#callObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mosaik/commands/extract.rb', line 35

def call
  info "Extracting information from the codebase (#{options.map { |k, v| "#{k}: #{v}" }.join(', ')})"

  warn "No files found in the load paths, check if a valid mosaik.yml file exists in #{options[:directory]}" if MOSAIK.configuration.files.empty?

  # Add a vertex for each constant in the load path
  MOSAIK.configuration.files.each do |file|
    # Resolve file path to class name
    class_name = resolver.resolve_file(file)

    # Add class to graph
    graph.find_or_add_vertex(class_name)
  end

  # Extract structural coupling information and add to graph
  if options[:couplings].include?(:structural)
    Extractors::Structural
      .new(options, graph)
      .tap(&:validate)
      .call
  end

  # Extract evolutionary (logical and contributor) coupling information and add to graph
  if options[:couplings].include?(:logical) || options[:couplings].include?(:contributor)
    Extractors::Evolution
      .new(options, graph)
      .tap(&:validate)
      .call
  end

  # Write graph to file
  write_graph

  # Render graph visualization
  visualize_graph
end

#validateObject

Raises:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mosaik/commands/extract.rb', line 23

def validate
  super

  couplings = options[:couplings] - self.class.defaults[:couplings]

  raise OptionError, "unknown coupling: #{couplings.join(', ')}" unless couplings.empty?

  raise OptionError, "negative value: #{options[:limit]}" if options[:limit].negative?

  options[:limit] = nil if options[:limit].zero?
end