summaryrefslogtreecommitdiff
path: root/internal/processor/card_store.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-06 11:12:03 +0300
committerPaul Buetow <paul@buetow.org>2026-04-06 11:12:03 +0300
commit616beecc41b573503dad9f5bfd9f353c6f826a8a (patch)
tree3189ae3f048dfc4e8ff79b83caab8ea43c2d7492 /internal/processor/card_store.go
parent05f54cc0cb8cf3535698ab5027d200842bdb28e3 (diff)
refactor: extract shared CardStore into internal/store to eliminate duplication
FindCardDirectory, FindOrCreateCardDirectory, GenerateCardID and the ScanWords helper previously existed in both internal/utils.go (as standalone functions) and were partially duplicated in internal/gui/card_service.go (readWordFromDir, ScanExistingWords). Introduce internal/store.CardStore as the single source of truth for all on-disk card-directory operations. Both internal/processor and internal/gui now hold a *store.CardStore field and delegate to it, removing the last copy of the directory-scanning loop from card_service.go. internal/utils.go keeps thin forwarding wrappers for callers that import the root internal package. Also adds table-driven unit tests for the new package covering FindCardDirectory (including legacy _word.txt fallback), FindOrCreateCardDirectory, and CardStore.ScanWords. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/processor/card_store.go')
-rw-r--r--internal/processor/card_store.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/internal/processor/card_store.go b/internal/processor/card_store.go
index 1020998..25b4e36 100644
--- a/internal/processor/card_store.go
+++ b/internal/processor/card_store.go
@@ -1,14 +1,14 @@
package processor
// CardStore manages the on-disk layout of word card directories.
-// It wraps the low-level internal.FindCardDirectory /
-// internal.FindOrCreateCardDirectory helpers and adds the higher-level
-// isWordFullyProcessed check used by the batch processor to skip words that
-// have already been completely generated.
+// It delegates to the shared store.CardStore (internal/store) for all
+// directory-discovery and creation logic, so those algorithms live in exactly
+// one place (DRY). The methods here add the higher-level isWordFullyProcessed
+// check that is specific to the batch processor.
//
-// All methods are on *Processor rather than a separate struct to avoid an
-// extra layer of indirection while still keeping the concerns separated into
-// their own file (SRP at the file level, as recommended for Go packages).
+// All methods are on *Processor rather than a separate struct to keep the
+// existing call sites unchanged while still separating concerns at the file
+// level (SRP at the file level, as recommended for Go packages).
import (
"os"
@@ -21,16 +21,17 @@ import (
)
// findOrCreateWordDirectory returns the existing card directory for word
-// inside the configured output directory, creating it when absent.
+// inside the configured output directory, creating it when absent. Delegates
+// to the shared CardStore so the directory-creation algorithm is not duplicated.
func (p *Processor) findOrCreateWordDirectory(word string) string {
- return internal.FindOrCreateCardDirectory(p.flags.OutputDir, word)
+ return p.cardStore.FindOrCreateCardDirectory(word)
}
// findCardDirectory searches the configured output directory for an existing
// card directory that contains the given word. Returns an empty string when
-// no matching directory is found.
+// no matching directory is found. Delegates to the shared CardStore.
func (p *Processor) findCardDirectory(word string) string {
- return internal.FindCardDirectory(p.flags.OutputDir, word)
+ return p.cardStore.FindCardDirectory(word)
}
// isWordFullyProcessed returns true when the word's card directory already