Class: Dataset::Database::Base

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/dataset/database/base.rb

Overview

Provides Dataset a way to clear, dump and load databases.

Direct Known Subclasses

Mysql, Postgresql, Sqlite3

Instance Method Summary collapse

Instance Method Details

#clearObject



10
11
12
13
14
15
16
17
18
# File 'lib/dataset/database/base.rb', line 10

def clear
  connection = ActiveRecord::Base.connection
  ActiveRecord::Base.silence do
    connection.tables.each do |table_name|
      connection.delete "DELETE FROM #{connection.quote_table_name(table_name)}",
        "Dataset::Database#clear" unless table_name == ActiveRecord::Migrator.schema_migrations_table_name
    end
  end
end

#record_heirarchy(record_class) ⇒ Object



20
21
22
23
# File 'lib/dataset/database/base.rb', line 20

def record_heirarchy(record_class)
  base_class = record_class.base_class
  record_heirarchies[base_class] ||= Dataset::Record::Heirarchy.new(base_class)
end

#record_meta(record_class) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/dataset/database/base.rb', line 25

def record_meta(record_class)
  record_metas[record_class] ||= begin
    heirarchy = record_heirarchy(record_class)
    heirarchy.update(record_class)
    Dataset::Record::Meta.new(heirarchy, record_class)
  end
end