Class: Lagoon::Parser::ControllerParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lagoon/parser/controller_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ControllerParser

Returns a new instance of ControllerParser.



8
9
10
11
12
# File 'lib/lagoon/parser/controller_parser.rb', line 8

def initialize(options = {})
  @options = options.is_a?(Options) ? options : Options.for(:controller, options)
  @analyzer = Lagoon::Analyzer::ActionControllerAnalyzer.new
  @filter = ApplicationClassFilter.new(directory: 'controllers', include_all: @options[:all_controllers])
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/lagoon/parser/controller_parser.rb', line 6

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/lagoon/parser/controller_parser.rb', line 6

def options
  @options
end

Instance Method Details

#parseObject



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
43
44
45
46
47
# File 'lib/lagoon/parser/controller_parser.rb', line 14

def parse
  controllers = load_controllers
  classes = []
  relationships = []

  warnings = []

  controllers.sort_by { |controller| controller.name.to_s }.each do |controller|
    next if excluded?(controller)

    controller_data = @analyzer.analyze_controller(controller, analysis_options)
    classes << controller_data

    if options[:include_inheritance]
      relationships.concat(
        @analyzer.extract_inheritance(
          controller,
          include_framework_base: options[:include_framework_bases]
        )
      )
    end
  rescue StandardError => e
    raise if options[:strict]

    warnings << "Failed to analyze controller #{controller.name || '(anonymous)'}: #{e.message}"
  end

  {
    classes: classes.sort_by { |controller| controller[:name] },
    relationships: relationships.sort_by { |relationship| [relationship[:source], relationship[:target]] },
    warnings: warnings,
    counts: { classes: classes.size, relationships: relationships.size, skipped: warnings.size }
  }
end