Sha256: 5b2a06b7da4f6b2029a4ba2b41bdf2d2a03736b71e41c0cc30463c03c1da5be2

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'data_mapper'
require 'dm-migrations'
require 'active_support/time_with_zone'
require File.dirname(__FILE__) + '/channel'
require File.dirname(__FILE__) + '/programme'
require File.dirname(__FILE__) + '/programme_category'
require File.dirname(__FILE__) + '/programme_director'
require File.dirname(__FILE__) + '/programme_presenter'
require File.dirname(__FILE__) + '/programme_actor'
require File.dirname(__FILE__) + '/schedule'
require File.dirname(__FILE__) + '/recording'

DataMapper.finalize

module SimplePvr
  module Model
    class DatabaseInitializer
      def self.setup(database_file_name = nil)
        database_file_name ||= Dir.pwd + '/database.sqlite'
        DataMapper.setup(:default, "sqlite://#{database_file_name}")
        DataMapper.auto_upgrade!
      end
    
      def self.clear
        Schedule.destroy
        ProgrammeCategory.destroy
        ProgrammePresenter.destroy
        ProgrammeDirector.destroy
        ProgrammeActor.destroy
        Programme.destroy
        Channel.destroy
      end
    
      def self.prepare_for_test
        return if @initialized
      
        @database_file_name = Dir.pwd + '/spec/resources/test.sqlite'
        File.delete(@database_file_name) if File.exists?(@database_file_name)
        self.setup(@database_file_name)
        @initialized = true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_pvr-1.1.0 lib/simple_pvr/model/database_initializer.rb