Module: Rmre::DynamicDb

Included in:
Source, Target
Defined in:
lib/rmre/dynamic_db.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/rmre/dynamic_db.rb', line 5

def self.included(base)
  base.send :extend, Rmre::DynamicDb
end

Instance Method Details

#connection_optionsObject



9
10
11
# File 'lib/rmre/dynamic_db.rb', line 9

def connection_options
  @connection_options
end

#connection_options=(v) ⇒ Object



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

def connection_options= v
  @connection_options = v
end

#create_model_for(table_name, primary_key_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rmre/dynamic_db.rb', line 17

def create_model_for(table_name, primary_key_name)
  model_name = table_name.classify
  module_eval <<-ruby_src, __FILE__, __LINE__ + 1
    class #{model_name} < Db
      self.table_name = '#{table_name}'
      establish_connection(#{connection_options})
    end
  ruby_src
  klass = const_get model_name
  klass.primary_key = primary_key_name if primary_key_name && primary_key_name != 'id'
  klass
end