Class: RailsAiBridge::Introspectors::ModelIntrospector::CallbackExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/introspectors/model_introspector/callback_extractor.rb

Overview

Extracts callback metadata from an ActiveRecord model.

Iterates over standard ActiveRecord callback types (before/after validation, save, create, update, destroy, commit, rollback) and collects named callback filters, excluding framework-generated entries and Proc-based callbacks.

Constant Summary collapse

CALLBACK_TYPES =
%i[
  before_validation after_validation
  before_save after_save
  before_create after_create
  before_update after_update
  before_destroy after_destroy
  after_commit after_rollback
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(model, excluded_prefixes:) ⇒ CallbackExtractor

Returns a new instance of CallbackExtractor.

Parameters:

  • model (Class)

    ActiveRecord model class

  • excluded_prefixes (Array<String>)

    callback name prefixes to skip



24
25
26
27
# File 'lib/rails_ai_bridge/introspectors/model_introspector/callback_extractor.rb', line 24

def initialize(model, excluded_prefixes:)
  @model = model
  @excluded_prefixes = excluded_prefixes
end

Instance Method Details

#callHash<String, Array<String>>

Returns callbacks grouped by type.

Returns:

  • (Hash<String, Array<String>>)

    callbacks grouped by type



30
31
32
33
34
35
36
37
# File 'lib/rails_ai_bridge/introspectors/model_introspector/callback_extractor.rb', line 30

def call
  CALLBACK_TYPES.each_with_object({}) do |type, hash|
    names = callback_names_for(type)
    hash[type.to_s] = names unless names.empty?
  end
rescue StandardError
  {}
end