module Smartdict::Storage

Public Instance Methods

prepare!() click to toggle source
# File lib/smartdict/storage.rb, line 9
def prepare!
  #DataMapper::Logger.new(STDOUT, :debug)
  setup_sqlite
  update_enums_cache
end

Private Instance Methods

db_file() click to toggle source
# File lib/smartdict/storage.rb, line 41
def db_file
  "#{Smartdict.user_dir}/database.sqlite"
end
migrate_and_seed?() click to toggle source
# File lib/smartdict/storage.rb, line 37
def migrate_and_seed?
  storage_line =~ /memory/ or !File.exists?(db_file)
end
setup_sqlite() click to toggle source
# File lib/smartdict/storage.rb, line 18
def setup_sqlite
  DataMapper.setup(:default, storage_line)
  DataMapper.finalize
  if migrate_and_seed?
    DataMapper.auto_migrate!
    Seeder.seed!
  end
end
storage_line() click to toggle source
# File lib/smartdict/storage.rb, line 33
def storage_line
  (Smartdict.env == :test) ? "sqlite::memory:" : "sqlite://#{db_file}"
end
update_enums_cache() click to toggle source
# File lib/smartdict/storage.rb, line 27
def update_enums_cache
  [Language, Driver, WordClass].each do |model_class|
    model_class.update_enums_cache!
  end
end