Sha256: 7ed6e81439ac8d007dbe24342e43b42592861737a04c6db6c3cf631a562921b8

Contents?: true

Size: 939 Bytes

Versions: 46

Compression:

Stored size: 939 Bytes

Contents

module Dataset
  module Database # :nodoc:
    
    # The interface to a sqlite3 database, this will capture by copying the db
    # file and restore by replacing and reconnecting to one of the same.
    #
    class Sqlite3 < Base
      def initialize(database_spec, storage_path)
        @database_path, @storage_path = database_spec[:database], storage_path
        FileUtils.mkdir_p(@storage_path)
      end
      
      def capture(datasets)
        return if datasets.nil? || datasets.empty?
        cp @database_path, storage_path(datasets)
      end
      
      def restore(datasets)
        store = storage_path(datasets)
        if File.file?(store)
          mv store, @database_path
          ActiveRecord::Base.establish_connection 'test'
          true
        end
      end
      
      def storage_path(datasets)
        "#{@storage_path}/#{datasets.collect {|c| c.__id__}.join('_')}.sqlite3.db"
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 8 rubygems

Version Path
aiwilliams-dataset-1.2.0 lib/dataset/database/sqlite3.rb
aiwilliams-dataset-1.3.0 lib/dataset/database/sqlite3.rb
aiwilliams-dataset-1.3.1 lib/dataset/database/sqlite3.rb
karsthammer-dataset-1.2.0 lib/dataset/database/sqlite3.rb
radiant-1.1.4 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.3 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.2 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.1 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.0 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.0.rc1 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.0.beta vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.1 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.1.0.alpha vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.0 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.0.rc5 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.0.rc4 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.0.rc3 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
kajam-1.0.3.rc2 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.0.rc2 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb
radiant-1.0.0.rc1 vendor/plugins/dataset/lib/dataset/database/sqlite3.rb