class ActiveOrient::Model
Attributes
abstract[RW]
ref_name[RW]
metadata[R]
mattr_accessor :ref_name
Used to read the metadata
Public Class Methods
autoload_object(rid)
click to toggle source
Either retrieves the object from the rid_store or loads it from the DB.
Example:
ActiveOrient::Model.autoload_object "#00:00"
The rid_store is updated!
Todo: fetch for version in the db and load the object only if a change is detected
Note: This function is not located in ModelClass
since it needs to use @@rid_store
# File lib/model/model.rb, line 26 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 get(rid) end else logger.progname = "ActiveOrient::Model#AutoloadObject" logger.info{"#{rid} is not a valid rid."} end end
delete_class(what= :all)
click to toggle source
Deletes the database class and removes the ruby-class
# File lib/model/model.rb, line 87 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
to_or()
click to toggle source
# File lib/model/model.rb, line 127 def to_or ref_name.to_or end
use_or_allocate(rid) { || ... }
click to toggle source
Based on the parameter rid (as “#{a}:{b}” or “{a}:{b}”) the cached value is used if found. Otherwise the provided Block is executed, which is responsible for the allocation of a new dataset
i.e.
ActiveOrient::Model.use_or_allocated my_rid do ActiveOrient::Model.orientdb_class(name: raw_data['@class']).new raw_data end
# File lib/model/model.rb, line 58 def self.use_or_allocate rid cached_obj = get_rid( rid ) if cached_obj.present? cached_obj else yield end end
Public Instance Methods
persisted?()
click to toggle source
used for active-model-compatibility
# File lib/model/model.rb, line 41 def persisted? true end