class BomDB::Import::Base
Attributes
db[R]
opts[R]
Public Class Methods
new(db, **opts)
click to toggle source
# File lib/bomdb/import/base.rb, line 8 def initialize(db, **opts) @db = db @opts = opts end
tables(*tables)
click to toggle source
# File lib/bomdb/import/base.rb, line 13 def self.tables(*tables) @tables = tables end
Public Instance Methods
ensure_parsed_json(data)
click to toggle source
# File lib/bomdb/import/base.rb, line 46 def ensure_parsed_json(data) if data.is_a?(String) JSON.parse(data) else data end end
import(data, format: 'json')
click to toggle source
# File lib/bomdb/import/base.rb, line 21 def import(data, format: 'json') if !schema.has_tables?(tables) return Import::Result.new( success: false, error: "Database table(s) not present: [#{tables.join(', ')}]" ) end import_before() if respond_to?(:import_before) result = case format when 'json' then import_json(ensure_parsed_json(data)) when 'text' then import_text(data) else return Import::Result.new( success: false, error: "Unknown format: #{format}" ) end import_after() if respond_to?(:import_after) result end
schema()
click to toggle source
# File lib/bomdb/import/base.rb, line 54 def schema BomDB::Schema.new(@db) end
tables()
click to toggle source
# File lib/bomdb/import/base.rb, line 17 def tables self.class.instance_variable_get("@tables") end