Class: DbBackupTool::Mappers::ActiveRecordMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/db_backup_tool/mappers/active_record_mapper.rb

Defined Under Namespace

Classes: Table

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ActiveRecordMapper

Constructor



6
7
8
9
10
11
# File 'lib/db_backup_tool/mappers/active_record_mapper.rb', line 6

def initialize(config)
  @orm = Class.new(ActiveRecord::Base) {
    self.abstract_class = true
    establish_connection(config)
  }
end

Instance Method Details

#connectionObject

:internal



14
15
16
# File 'lib/db_backup_tool/mappers/active_record_mapper.rb', line 14

def connection
  @orm.connection
end

#tablesObject

Return tables (proxy) in the database



19
20
21
22
23
# File 'lib/db_backup_tool/mappers/active_record_mapper.rb', line 19

def tables
  table_names = @orm.connection.tables.dup
  table_names.reject! {|t| %w(schema_info schema_migrations).include? t }
  Hash[ table_names.map {|t| [t, Table.new(@orm, t)] } ].freeze
end