Class: MyStuff::MultiDB::Connection

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/my_stuff/multidb/connection.rb

Class Method Summary collapse

Class Method Details

.abstract_class?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/my_stuff/multidb/connection.rb', line 27

def abstract_class?
  true
end

.base_class_for_spec(spec) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/my_stuff/multidb/connection.rb', line 15

def base_class_for_spec spec
  name = MyStuff::MultiDB::Mangling.mangle(spec).to_sym
  if Connections.const_defined?(name)
    return Connections.const_get(name)
  end

  connection = Class.new(self)
  Connections.const_set(name, connection)
  connection.establish_connection(spec)
  connection
end

.rebased_model(name, original_module, rebased_module) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/my_stuff/multidb/connection.rb', line 41

def rebased_model name, original_module, rebased_module
  if rebased_module.const_defined? name
    rebased_module.const_get(name)
  else
    self.rebase_model! name, original_module, rebased_module
  end
end

.rebased_module(original_module) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/my_stuff/multidb/connection.rb', line 31

def rebased_module original_module
  name = original_module.name.gsub(':', '__').to_sym

  if have_rebased_module?(name)
    self.const_get(name)
  else
    self.rebase_module! name, original_module
  end
end