Module: Iriq::Storage
- Defined in:
- lib/iriq/storage.rb,
lib/iriq/storage/json.rb,
lib/iriq/storage/memory.rb,
lib/iriq/storage/sqlite.rb
Overview
Storage is the persistence layer for a Corpus. It owns every counter and per-(host, prefix) frequency map; the Corpus class delegates state to it.
Three concrete backends ship:
Storage::Memory — in-memory only; matches the original behavior.
Storage::Json — Memory backend wrapped with load/save against a JSON file.
Storage::Sqlite — incremental UPSERTs against a SQLite database.
File-extension dispatch keeps callers simple: ‘.json` (or anything else) picks Json, `.db`/`.sqlite`/`.sqlite3` picks Sqlite.
Defined Under Namespace
Constant Summary collapse
- SQLITE_EXTS =
%w[.db .sqlite .sqlite3].freeze
Class Method Summary collapse
-
.open(path, classifier: SegmentClassifier::DEFAULT, max_values_per_position: PositionStats::DEFAULT_MAX_VALUES) ⇒ Object
Opens (or creates) a storage at ‘path`, picking the backend by extension.
Class Method Details
.open(path, classifier: SegmentClassifier::DEFAULT, max_values_per_position: PositionStats::DEFAULT_MAX_VALUES) ⇒ Object
Opens (or creates) a storage at ‘path`, picking the backend by extension. If `path` is nil, returns a Memory backend.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/iriq/storage.rb', line 20 def open(path, classifier: SegmentClassifier::DEFAULT, max_values_per_position: PositionStats::DEFAULT_MAX_VALUES) return Memory.new(classifier: classifier, max_values_per_position: max_values_per_position) if path.nil? if SQLITE_EXTS.include?(File.extname(path).downcase) require "iriq/storage/sqlite" Sqlite.open(path, classifier: classifier, max_values_per_position: max_values_per_position) else require "iriq/storage/json" Json.open(path, classifier: classifier, max_values_per_position: max_values_per_position) end end |