I'm working on a reporting and logging system that'll act as a viewport on the statistics of other applications. I want the ORM functionality of ActiveRecord, but do not have the DB structures of apps before hand.
The extra databases are defined in database.yml and I then connect with a class.
class externalapp < ActiveRecord::Base
establish_connection :externalapp_db
end
def create_class(class_name, superclass, &block)
klass = Class.new superclass, &block
Object.const_set class_name, klass
end
I need to be able to
- Create classes (from tables) on the fly and
- have them map to external database's tables
Am I approaching this incorrectly? How can I go about better namespacing the external databases, whilst allowing for dynamic class creation.
Suggestions and help appreciated.