require_relative "the_class.rb" require_relative "the_record.rb" module ActiveOrient class Model < ActiveOrient::Base include BaseProperties include ModelRecord # For objects (file: lib/record.rb) extend ModelClass # For classes =begin Example: ActiveOrient::Model.autoload_object "#00:00" either retrieves the object from the rid_store or loads it from the DB. The rid_store is updated! To_do: fetch for version in the db and load the object if a change is detected Note: This function is not in ModelClass since it needs to use @@rid_store =end def self.autoload_object rid rid = rid[1..-1] if rid[0]=='#' if rid.rid? if @@rid_store[rid].present? @@rid_store[rid] # return_value else db.get_record(rid) end else logger.progname = "ActiveOrient::Model#AutoloadObject" logger.info{"#{rid} is not a valid rid."} end end ## to prevent errors when calling to_a def to_ary # :nodoc: attributes.to_a end def document # :nodoc: @d end =begin Deletes the database class and removes the ruby-class =end def self.delete_class what= :all orientdb.delete_class( self ) if what == :all # remove the database-class ## namespace is defined in config/boot ns = namespace.to_s == 'Object' ? "" : namespace.to_s ns_found = -> ( a_class ) do to_compare = a_class.to_s.split(':') if ns == "" && to_compare.size == 1 true elsif to_compare.first == ns true else false end end self.allocated_classes.delete_if{|x,y| x == self.ref_name && ns_found[y]} if allocated_classes.is_a?(Hash) namespace.send(:remove_const, naming_convention.to_sym) if namespace.send( :const_defined?, naming_convention) end # provides an unique accessor on the Class # works with a class-variable, its unique through all Subclasses mattr_accessor :orientdb # points to the instance of the REST-DB-Client used for Administration # i.e. creation and deleting of classes and databases mattr_accessor :db # points to the instance of the Client used for Database-Queries mattr_accessor :api # mattr_accessor :logger ... already inherented from ::Base mattr_accessor :namespace # Namespace in which Model records are initialized, a constant ( defined in config.yml ) mattr_accessor :model_dir # path to model-files mattr_accessor :keep_models_without_file mattr_accessor :allocated_classes # mattr_accessor :ref_name # Used to read the metadata attr_reader :metadata # provides an accessor at class level # its unique on all instances class << self attr_accessor :ref_name attr_accessor :abstract end end end