Module: LcpRuby::Metadata::ModelInheritanceResolver

Defined in:
lib/lcp_ruby/metadata/model_inheritance_resolver.rb

Overview

Resolves model inheritance by merging parent hashes into child hashes. Supports two inheritance modes:

1. Abstract inheritance: parent is abstract, child gets merged fields, parent is removed
2. STI inheritance: parent has options.sti: true, child shares parent's table via AR STI

Input: { name => { hash:, source_path:, source_type: } } Output: resolved entries with abstract models removed; STI models preserved with metadata.

Constant Summary collapse

STI_CHILD_KEY =
"_sti_child"

Class Method Summary collapse

Class Method Details

.resolve(entries) ⇒ Object



13
14
15
16
17
# File 'lib/lcp_ruby/metadata/model_inheritance_resolver.rb', line 13

def self.resolve(entries)
  validate_inheritance_targets!(entries)
  sorted = topological_sort(entries)
  merge_and_filter(sorted, entries)
end

.sort_definitions(model_definitions) ⇒ Object

Sorts ModelDefinition objects so STI parents are built before children. Used by Engine and integration tests after definitions are created.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lcp_ruby/metadata/model_inheritance_resolver.rb', line 21

def self.sort_definitions(model_definitions)
  sorted = []
  visited = Set.new

  visit = lambda do |model_def|
    return if visited.include?(model_def.name)
    visited.add(model_def.name)

    if (parent_name = model_def.sti_parent_name)
      parent_def = model_definitions[parent_name]
      visit.call(parent_def) if parent_def
    end

    sorted << model_def
  end

  model_definitions.each_value { |md| visit.call(md) }
  sorted
end