Own cache_dir in Rakefile, pass output_dir into Capture
Capture no longer knows where it lives — the Rakefile decides.

Assisted-by: Claude Opus 4.6 via Claude Code
change tmkqvoposuotnzkrkmlssqrorwrsrltl
commit a3b9de9156a4d55b60882a49b19b8c55d5f6f9f8
author Alpha Chen <alpha@kejadlen.dev>
date
parent xuvntxzl
diff --git a/Rakefile b/Rakefile
index f817ad7..a653d20 100644
--- a/Rakefile
+++ b/Rakefile
@@ -119,12 +119,12 @@ namespace :snapshots do
     ENV["DATABASE_URL"] = ":memory:"
     require "ketchup/snapshots"
 
-    capture = Ketchup::Snapshots::Capture.new
-    capture.call
+    output_dir = File.join(cache_dir, "current")
+    Ketchup::Snapshots::Capture.new(output_dir: output_dir).call
 
     if ENV["CI"]
       require "json"
-      puts({ output_dir: capture.output_dir }.to_json)
+      puts({ output_dir: output_dir }.to_json)
     end
   end
 
@@ -132,7 +132,7 @@ namespace :snapshots do
   task diff: [:capture, *css_targets] do
     require "erb"
 
-    base_dir = Ketchup::Snapshots.cache_dir
+    base_dir = cache_dir
     baseline_dir = File.join(base_dir, "baseline")
     current_dir = File.join(base_dir, "current")
 
@@ -177,7 +177,7 @@ namespace :snapshots do
 
   desc "Capture, diff, and open the viewer"
   task review: :diff do
-    system("open", File.join(Ketchup::Snapshots.cache_dir, "diff.html"))
+    system("open", File.join(cache_dir, "diff.html"))
   end
 
   desc "Generate gallery HTML from images in a directory"
diff --git a/lib/ketchup/snapshots.rb b/lib/ketchup/snapshots.rb
index b54600a..ca8e9ff 100644
--- a/lib/ketchup/snapshots.rb
+++ b/lib/ketchup/snapshots.rb
@@ -11,16 +11,9 @@ require_relative "web"
 
 module Ketchup
   module Snapshots
-    def self.cache_dir
-      base = ENV.fetch("XDG_CACHE_HOME", File.expand_path("~/.cache"))
-      File.join(base, "ketchup", "snapshots")
-    end
-
     class Capture
-      attr_reader :output_dir
-
-      def initialize(logger: Logger.new($stderr))
-        @output_dir = File.join(Snapshots.cache_dir, "current")
+      def initialize(output_dir:, logger: Logger.new($stderr))
+        @output_dir = output_dir
         @logger = logger
       end