Class: RailsAiBridge::Introspectors::GemIntrospector

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

Overview

Analyzes Gemfile.lock to identify installed gems and map them to known patterns/frameworks the AI should know about.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ GemIntrospector

Returns a new instance of GemIntrospector.



10
11
12
# File 'lib/rails_ai_bridge/introspectors/gem_introspector.rb', line 10

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



8
9
10
# File 'lib/rails_ai_bridge/introspectors/gem_introspector.rb', line 8

def app
  @app
end

Instance Method Details

#callHash

Parse +Gemfile.lock+ and classify notable gems.

Returns +{ error: message }+ for any rescued +StandardError+ — including a missing or unreadable lockfile, malformed content, or any other runtime exception — so callers always receive a controlled hash rather than an unhandled exception.

Returns:

  • (Hash)

    gem analysis with +:total_gems+, +:ruby_version+, +:notable_gems+, and +:categories+ on success; or +{ error: String }+ on any rescued +StandardError+



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_ai_bridge/introspectors/gem_introspector.rb', line 24

def call
  lock_path = File.join(app.root, 'Gemfile.lock')
  return { error: 'No Gemfile.lock found' } unless File.exist?(lock_path)

  specs   = parse_lockfile(lock_path)
  notable = detect_notable_gems(specs)

  {
    total_gems: specs.size,
    ruby_version: specs['ruby']&.first,
    notable_gems: notable,
    categories: GemRegistry.categorize(notable)
  }
rescue StandardError => error
  { error: "GemIntrospector failed: #{error.class}" }
end