Module: DbCharmer::DbMagic::ClassMethods

Defined in:
lib/db_charmer/db_magic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(child) ⇒ Object



28
29
30
31
# File 'lib/db_charmer/db_magic.rb', line 28

def self.inherited(child)
  child.db_magic(self.db_charmer_opts)
  super
end

Instance Method Details

#db_magic(opt = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/db_charmer/db_magic.rb', line 4

def db_magic(opt = {})
  # Make sure we could use our connections management here
  hijack_connection!

  # Should requested connections exist in the config?
  should_exist = opt[:should_exist] || DbCharmer.connections_should_exist?

  # Main connection management
  db_magic_connection(opt[:connection], should_exist) if opt[:connection]

  # Set up slaves pool
  opt[:slaves] ||= []
  opt[:slaves] << opt[:slave] if opt[:slave]
  db_magic_slaves(opt[:slaves], should_exist) if opt[:slaves].any?
  
  # Setup inheritance magic
  setup_children_magic(opt)
end