Class: Ordinals::Cache
- Inherits:
-
Object
- Object
- Ordinals::Cache
- Defined in:
- lib/ordlite/cache.rb
Constant Summary collapse
- Inscribe =
OrdDb::Model::Inscribe
- Blob =
OrdDb::Model::Blob
Instance Method Summary collapse
Instance Method Details
#import(id) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/ordlite/cache.rb', line 51 def import( id ) data = read( id ) rec = Inscribe.find_by( id: id ) if rec # skip - already in db else rec = Inscribe.create_from_cache( data ) end end |
#import_all ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ordlite/cache.rb', line 9 def import_all paths = puts " #{paths.size} inscribe metaddatafile(s) found" paths.each_with_index do |path, i| ## puts "==> inscribe #{i+1}/#{paths.size}..." data = _read_inscribe( path ) id = data['id'] ## skip if exists (use update later - why? why not?) rec = Inscribe.find_by( id: id ) if rec ## skip - already in db print '.' else print " #{id}" # NEW - add / insert into db" rec = Inscribe.create_from_cache( data ) end end puts paths = _find_blobs puts " #{paths.size} inscribe blob(s) found" paths.each_with_index do |path, i| ## puts "==> blob #{i+1}/#{paths.size}..." content = read_blob( path ) id = File.basename( File.dirname(path)) + File.basename( path, File.extname( path )) rec = Blob.find_by( id: id ) if rec ## skip - already in db print '.' else print " #{id}" # NEW - add / insert into db" rec = Blob.create( id: id, content: content ) end end puts end |