Class: Lagoon::Parser::ModelParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ModelParser

Returns a new instance of ModelParser.



12
13
14
15
16
# File 'lib/lagoon/parser/model_parser.rb', line 12

def initialize(options = {})
  @options = options.is_a?(Options) ? options : Options.for(:model, options)
  @analyzer = Lagoon::Analyzer::ActiveRecordAnalyzer.new
  @filter = ApplicationClassFilter.new(directory: 'models', include_all: @options[:all_models])
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/lagoon/parser/model_parser.rb', line 10

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/lagoon/parser/model_parser.rb', line 10

def options
  @options
end

Instance Method Details

#parseObject



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/lagoon/parser/model_parser.rb', line 18

def parse
  models = load_models
  classes = []
  relationships = []

  warnings = []

  models.sort_by { |model| model.name.to_s }.each do |model|
    next if excluded?(model)

    analyze_model(model, classes, relationships)
  rescue StandardError => e
    raise if options[:strict]

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

  normalized_relationships = deduplicate_relationships(relationships)
  {
    classes: classes.sort_by { |model| model[:name] },
    relationships: normalized_relationships,
    warnings: warnings,
    counts: { classes: classes.size, relationships: normalized_relationships.size, skipped: warnings.size }
  }
end