Class: RailsLens::ExtensionLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_lens/extension_loader.rb

Class Method Summary collapse

Class Method Details

.apply_extensions(model_class) ⇒ Object



30
31
32
33
34
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
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rails_lens/extension_loader.rb', line 30

def apply_extensions(model_class)
  results = {
    annotations: [],
    notes: [],
    erd_additions: {
      relationships: [],
      badges: [],
      attributes: {}
    }
  }

  load_extensions.each do |extension_class|
    next unless extension_class.detect?
    next unless extension_class.compatible?

    extension = extension_class.new(model_class)

    # Collect annotations with individual error handling
    begin
      if (annotation = extension.annotate)
        results[:annotations] << annotation
      end
    rescue StandardError => e
      log_extension_method_error(extension_class, 'annotate', e, model_class)
    end

    # Collect notes with individual error handling
    begin
      notes = extension.notes
      results[:notes].concat(notes) if notes.is_a?(Array)
    rescue StandardError => e
      log_extension_method_error(extension_class, 'notes', e, model_class)
    end

    # Collect ERD additions with individual error handling
    begin
      erd = extension.erd_additions
      if erd.is_a?(Hash)
        results[:erd_additions][:relationships].concat(erd[:relationships] || [])
        results[:erd_additions][:badges].concat(erd[:badges] || [])
        results[:erd_additions][:attributes].merge!(erd[:attributes] || {})
      end
    rescue StandardError => e
      log_extension_method_error(extension_class, 'erd_additions', e, model_class)
    end
  rescue StandardError => e
    log_extension_error("Failed to initialize or detect extension #{extension_class}: #{e.message}",
                        extension_class.gem_name)
  end

  results
end

.find_extension_for(_model_class) ⇒ Object



24
25
26
27
28
# File 'lib/rails_lens/extension_loader.rb', line 24

def find_extension_for(_model_class)
  load_extensions.find do |extension_class|
    extension_class.detect? && extension_class.compatible?
  end
end

.load_extensionsObject



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

def load_extensions
  return [] unless extensions_enabled?

  extensions = []

  # Load built-in extensions
  extensions.concat(load_builtin_extensions)

  # Load gem-provided extensions
  extensions.concat(load_gem_extensions) if autoload_enabled?

  # Load custom extensions
  extensions.concat(load_custom_extensions)

  # Filter out ignored extensions
  extensions.reject { |ext| ignored?(ext) }
end