Module: RubynCode::Learning::Porter
- Defined in:
- lib/rubyn_code/learning/porter.rb
Overview
Exports and imports learned instincts so a user can carry their accumulated learnings to another machine. Instincts live in SQLite under ~/.rubyn-code; this serializes them to a portable JSON file and loads them back, regenerating ids and de-duplicating by (project_path, pattern).
Defined Under Namespace
Classes: Error
Constant Summary collapse
- FORMAT_VERSION =
1- COLUMNS =
Columns carried across machines (id is regenerated on import).
%w[ project_path pattern context_tags confidence decay_rate times_applied times_helpful created_at updated_at ].freeze
Class Method Summary collapse
-
.export(db:, path:, project_path: nil) ⇒ Integer
Export instincts to a JSON file.
-
.import(db:, path:, remap_project: nil) ⇒ Hash
Import instincts from a JSON file.
-
.stats(db, project_path: nil) ⇒ Hash
{ count:, projects: } summary for display.
Class Method Details
.export(db:, path:, project_path: nil) ⇒ Integer
Export instincts to a JSON file.
29 30 31 32 33 34 |
# File 'lib/rubyn_code/learning/porter.rb', line 29 def export(db:, path:, project_path: nil) rows = fetch(db, project_path) payload = { 'version' => FORMAT_VERSION, 'instincts' => rows } File.write(path, "#{JSON.pretty_generate(payload)}\n") rows.size end |
.import(db:, path:, remap_project: nil) ⇒ Hash
Import instincts from a JSON file.
43 44 45 46 47 48 49 50 51 |
# File 'lib/rubyn_code/learning/porter.rb', line 43 def import(db:, path:, remap_project: nil) raise Error, "File not found: #{path}" unless File.file?(path) payload = parse(path) instincts = Array(payload['instincts']) imported = instincts.count { |row| import_row(db, row, remap_project) } { imported: imported, skipped: instincts.size - imported, total: instincts.size } end |
.stats(db, project_path: nil) ⇒ Hash
Returns { count:, projects: } summary for display.
54 55 56 57 |
# File 'lib/rubyn_code/learning/porter.rb', line 54 def stats(db, project_path: nil) rows = fetch(db, project_path) { count: rows.size, projects: rows.map { |r| r['project_path'] }.uniq.size } end |