Skip to content

Instantly share code, notes, and snippets.

@gmarik
Created November 14, 2010 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmarik/675814 to your computer and use it in GitHub Desktop.
Save gmarik/675814 to your computer and use it in GitHub Desktop.
crap
# Return the directories where we need to load configuration files
def process_model_dirs(app_manifest_filename=nil)
File.open(app_manifest_filename).each do |line|
str = line.chomp
if str != nil and str.length > 0
#puts "model file: #{str}"
modelName = File.basename(File.dirname(str))
Rhom::RhomObjectFactory.init_object(modelName)
require str
#puts "model name: #{modelName}"
modelClass = Object.const_get(modelName)
if modelClass
if modelClass.respond_to?( :get_model_params )
Rho::RhoConfig::add_source(modelName,modelClass.get_model_params())
modelClass.reset_model_params()
else
puts "ERROR: Invalid model definition. Add 'include Rhom::PropertyBag' or 'include Rhom::FixedSchema' to model class"
end
else
puts "ERROR: cannot load model : #{modelClass}"
end
end
require 'rhodes'
module Rhom
class RhomDbAdapter
@database = nil
# maintains a single database connection
def initialize(dbfile, partition)
unless @database
@database = SQLite3::Database.new(dbfile,partition)
end
end
#..
end
# Initialize new object with dynamic attributes
def self.init_object(classname)
#Rho::RhoConfig.sources.each do |classname,source|
unless Object.const_defined?(classname.intern)
Object.const_set(classname.intern,
Class.new do
include ::Rhom::RhomObject
extend ::Rhom::RhomObject
# This holds the attributes for an instance of
# the rhom object
attr_accessor :vars
def generate_id
Rho::RhoConfig.generate_id()
end
def initialize(obj=nil)
@vars = {}
self.rhom_init(@vars)
self.vars[:object] = "#{generate_id()}" unless obj && obj[:object]
self.vars[:source_id] = self.get_inst_source_id.to_i
if obj
obj.each do |key,value|
self.vars[key.to_sym()] = value if key && key.length > 0
end
end
end
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment