Class: RailsLens::Analyzers::DelegatedTypes

Inherits:
Base
  • Object
show all
Defined in:
lib/rails_lens/analyzers/delegated_types.rb

Instance Attribute Summary

Attributes inherited from Base

#model_class

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from ErrorHandling

#safe_analyze

Constructor Details

This class inherits a constructor from RailsLens::Analyzers::Base

Instance Method Details

#analyzeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_lens/analyzers/delegated_types.rb', line 6

def analyze
  return nil unless delegated_type_model?

  lines = ['[delegated_type]']

  # Find delegated type configuration
  delegated_type_info = find_delegated_type_info
  return nil unless delegated_type_info

  lines << "type_column = \"#{delegated_type_info[:type_column]}\""
  lines << "id_column = \"#{delegated_type_info[:id_column]}\""
  types_list = if delegated_type_info[:types].respond_to?(:keys)
                 delegated_type_info[:types].keys
               else
                 Array(delegated_type_info[:types])
               end
  lines << "types = #{TomlFormat.quoted_array(types_list)}"

  lines.join("\n")
end