Class: ActiveOrient::Model

Inherits:
Base show all
Extended by:
CustomClass, ModelClass
Includes:
BaseProperties, ModelRecord
Defined in:
lib/model/model.rb

Direct Known Subclasses

E, V

Constant Summary

Constants included from OrientDB

OrientDB::DocumentDatabase, OrientDB::DocumentDatabasePool, OrientDB::DocumentDatabasePooled, OrientDB::GraphDatabase, OrientDB::IndexType, OrientDB::OClassImpl, OrientDB::OTraverse, OrientDB::PropertyImpl, OrientDB::RemoteStorage, OrientDB::SQLCommand, OrientDB::SQLSynchQuery, OrientDB::Schema, OrientDB::SchemaProxy, OrientDB::SchemaType, OrientDB::ServerAdmin, OrientDB::User, OrientDB::UsingJava

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModelClass

add_edge_link, all, alter_property, classname, count, create, create_class, create_index, create_properties, create_property, custom_where, delete_property, delete_record, delete_records, first, get, get_records, indexes, last, link_list, match, namespace_prefix, naming_convention, orientdb_class, print_properties, properties, query_database, require_model_file, update_all, upsert, where

Methods included from OrientSupport::Support

#compose_where, #generate_sql_list

Methods included from CustomClass

like

Methods included from BaseProperties

#==, #content_attributes, #default_attributes, #embedded, #set_attribute_defaults, #to_human, #update_missing

Methods inherited from Base

#[], #[]=, attr_accessible, attr_protected, #attributes, #attributes=, belongs_to, display_rid, exclude_the_following_properties, get_rid, has_many, has_one, #included_links, #initialize, #my_metadata, remove_rid, reset_rid_store, serialize, store_rid, #to_model, #update_attribute

Constructor Details

This class inherits a constructor from ActiveOrient::Base

Class Attribute Details

.abstractObject

Returns the value of attribute abstract


125
126
127
# File 'lib/model/model.rb', line 125

def abstract
  @abstract
end

.ref_nameObject

Returns the value of attribute ref_name


124
125
126
# File 'lib/model/model.rb', line 124

def ref_name
  @ref_name
end

Instance Attribute Details

#metadataObject (readonly)

Used to read the metadata


119
120
121
# File 'lib/model/model.rb', line 119

def 
  @metadata
end

Class Method Details

._to_partial_pathObject

:nodoc:


68
69
70
71
72
73
74
# File 'lib/model/model.rb', line 68

def self._to_partial_path #:nodoc:
  @_to_partial_path ||= begin
	element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name))
	collection = ActiveSupport::Inflector.tableize(name)
	"#{collection}/#{element}".freeze
   end
end

.autoload_object(rid) ⇒ Object

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


26
27
28
29
30
31
32
33
34
35
36
37
38
# 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) ⇒ Object

Deletes the database class and removes the ruby-class


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 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_orObject


127
128
129
# File 'lib/model/model.rb', line 127

def to_or
	ref_name.to_or
end

.use_or_allocate(rid) ⇒ Object

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

58
59
60
61
62
63
64
65
# 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

Instance Method Details

#documentObject

:nodoc:


80
81
82
# File 'lib/model/model.rb', line 80

def document  # :nodoc:
  @d
end

#persisted?Boolean

used for active-model-compatibility

Returns:

  • (Boolean)

41
42
43
# File 'lib/model/model.rb', line 41

def persisted?
  true
end

#to_aryObject

to prevent errors when calling to_a


76
77
78
# File 'lib/model/model.rb', line 76

def to_ary   # :nodoc:
  attributes.to_a
end