Class: RailsAiBridge::Introspectors::SemanticIntrospector

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

Overview

Dedicated semantic analysis introspector powered by rubydex.

Analyzes the entire codebase to extract:

  • Common implementation patterns
  • Semantic relationships between code elements
  • Complexity hotspots and frequently referenced areas
  • Codebase statistics

Returns an empty hash with an informational message when rubydex is not available or not enabled.

Constant Summary collapse

MAX_PATTERN_DECLARATIONS =

Maximum declarations to include in pattern detection to avoid huge payloads.

200
MAX_HOTSPOTS =

Maximum complexity hotspots to return.

20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SemanticIntrospector

Returns a new instance of SemanticIntrospector.



24
25
26
# File 'lib/rails_ai_bridge/introspectors/semantic_introspector.rb', line 24

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



16
17
18
# File 'lib/rails_ai_bridge/introspectors/semantic_introspector.rb', line 16

def app
  @app
end

Instance Method Details

#callHash

Builds a semantic analysis hash for the Rails application.

Returns:

  • (Hash)

    semantic analysis results or error/info hash



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_ai_bridge/introspectors/semantic_introspector.rb', line 31

def call
  config = RailsAiBridge.configuration
  unless config.rubydex_available?
    return { info: 'Rubydex is not available. Install the rubydex gem and set ' \
                   'config.rubydex_enabled = true to enable semantic analysis.' }
  end

  adapter = RubydexAdapter.instance(app.root.to_s)

  {
    codebase_stats: adapter.codebase_stats,
    patterns: detect_patterns(adapter),
    relationships: analyze_relationships(adapter),
    complexity_hotspots: find_complexity_hotspots(adapter)
  }
rescue StandardError => error
  msg = error.message
  Rails.logger.warn "[rails-ai-bridge] SemanticIntrospector failed: #{msg}"
  { error: msg }
end