Class: RailsAiBridge::Fingerprinter

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

Overview

Computes a SHA256 fingerprint of key application files to detect changes. Used by BaseTool to invalidate cached introspection when files change.

Constant Summary collapse

WATCHED_FILES =
%w[
  db/schema.rb
  config/routes.rb
  config/database.yml
  Gemfile.lock
].freeze
WATCHED_DIRS =
%w[
  app/models
  app/controllers
  app/views
  app/jobs
  app/mailers
  app/channels
  app/javascript/controllers
  app/middleware
  config/initializers
  db/migrate
  lib/tasks
].freeze

Class Method Summary collapse

Class Method Details

.changed?(app, previous) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rails_ai_bridge/fingerprinter.rb', line 56

def changed?(app, previous)
  snapshot(app) != previous
end

.compute(app) ⇒ Object



52
53
54
# File 'lib/rails_ai_bridge/fingerprinter.rb', line 52

def compute(app)
  snapshot(app)
end

.snapshot(app) ⇒ Object



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/fingerprinter.rb', line 31

def snapshot(app)
  root = app.root.to_s
  digest = Digest::SHA256.new

  WATCHED_FILES.each do |file|
    path = File.join(root, file)
    digest.update(File.mtime(path).to_f.to_s) if File.exist?(path)
  end

  WATCHED_DIRS.each do |dir|
    full_dir = File.join(root, dir)
    next unless Dir.exist?(full_dir)

    Dir.glob(File.join(full_dir, '**/*.{rb,rake,js,ts,erb,haml,slim,yml}')).each do |path|
      digest.update(File.mtime(path).to_f.to_s)
    end
  end

  digest.hexdigest
end