Module: ReversibleData

Defined in:
lib/reversible_data.rb,
lib/reversible_data/table.rb,
lib/reversible_data/rspec2_macros.rb,
lib/reversible_data/table_manager.rb,
lib/reversible_data/shoulda_macros.rb

Defined Under Namespace

Modules: RSpec2Macros, ShouldaMacros Classes: Table, TableManager

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



17
18
19
# File 'lib/reversible_data.rb', line 17

def self.[](name)
  Table.known_models[name]
end

.add(name, opts = {}, &blk) ⇒ Object



13
14
15
# File 'lib/reversible_data.rb', line 13

def self.add(name, opts = {}, &blk)
  Table.new(name, opts, &blk)
end

.connected? ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/reversible_data.rb', line 46

def self.connected?
  ActiveRecord::Base.connection.active?
rescue ActiveRecord::ConnectionNotEstablished
  false
end

.in_memory! ⇒ Object



38
39
40
41
42
43
44
# File 'lib/reversible_data.rb', line 38

def self.in_memory!
  if connected?
    ActiveRecord::Base.connection.disconnect!
    ActiveRecord::Base.remove_connection
  end
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
end

.manager_for(*tables) ⇒ Object



34
35
36
# File 'lib/reversible_data.rb', line 34

def self.manager_for(*tables)
  TableManager.new(*tables)
end

.remove(name) ⇒ Object



21
22
23
24
25
# File 'lib/reversible_data.rb', line 21

def self.remove(name)
  table = self[name]
  table.down!
  table.destroy
end

.remove_all ⇒ Object



27
28
29
30
31
32
# File 'lib/reversible_data.rb', line 27

def self.remove_all
  Table.known_models.each_value do |t|
    t.down!
    t.destroy
  end
end