Sha256: 6ddc8571477170ccc4b5036fe7044681886742ce6a74612fdf7e3e3ccb996735

Contents?: true

Size: 1.03 KB

Versions: 19

Compression:

Stored size: 1.03 KB

Contents

#!/usr/bin/env ruby
module Rtt
  module Storage

    DEFAULT_STORAGE_NAME = :rtt

    def export filename
      require 'fileutils'
      FileUtils.cp(File.join( File.dirname(__FILE__), '..', '..', 'db', "#{DEFAULT_STORAGE_NAME.to_s}.sqlite3"), filename)
    end

    def import filename
      require 'fileutils'
      FileUtils.cp(filename, File.join( File.dirname(__FILE__), '..', '..', 'db', "#{DEFAULT_STORAGE_NAME.to_s}.sqlite3"))
    end

    def init(database = :rtt)
      DataMapper.setup(:default, {:adapter => "sqlite3", :database => File.join( File.dirname(__FILE__), '..', '..', 'db', "#{database.to_s}.sqlite3") })
      migrate unless missing_tables
      #DataObjects::Sqlite3.logger = DataMapper::Logger.new(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'log', 'sqlite3.log')), 0)
    end

    def migrate #:nodoc:
      DataMapper.auto_migrate!
    end

    def missing_tables
      %W(rtt_projects rtt_users rtt_clients rtt_tasks).reject { |table| DataMapper.repository.storage_exists?(table) }.empty?
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rtt-0.0.0.47 lib/rtt/storage.rb
rtt-0.0.0.46 lib/rtt/storage.rb
rtt-0.0.0.45 lib/rtt/storage.rb
rtt-0.0.0.44 lib/rtt/storage.rb
rtt-0.0.0.43 lib/rtt/storage.rb
rtt-0.0.0.42 lib/rtt/storage.rb
rtt-0.0.0.41 lib/rtt/storage.rb
rtt-0.0.0.39 lib/rtt/storage.rb
rtt-0.0.0.38 lib/rtt/storage.rb
rtt-0.0.0.37 lib/rtt/storage.rb
rtt-0.0.0.36 lib/rtt/storage.rb
rtt-0.0.0.35 lib/rtt/storage.rb
rtt-0.0.0.33 lib/rtt/storage.rb
rtt-0.0.0.32 lib/rtt/storage.rb
rtt-0.0.0.31 lib/rtt/storage.rb
rtt-0.0.0.28 lib/rtt/storage.rb
rtt-0.0.0.27 lib/rtt/storage.rb
rtt-0.0.0.26 lib/rtt/storage.rb
rtt-0.0.0.25 lib/rtt/storage.rb