Class: E

Inherits:
ActiveOrient::Model show all
Defined in:
lib/model/edge.rb

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

Instance Attribute Summary

Attributes inherited from ActiveOrient::Model

#metadata

Attributes inherited from ActiveOrient::Base

#metadata

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveOrient::Model

_to_partial_path, autoload_object, delete_class, #document, #persisted?, #to_ary, to_or, use_or_allocate

Methods included from CustomClass

#like

Methods included from ModelClass

#add_edge_link, #all, #alter_property, #classname, #count, #create, #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 ModelRecord

classname, #find, #from_orient, #has_property?, #increment_version, #is_edge?, #method_missing, #properties, #query, #reload!, #rid, #rrid, #save, #to_or, #transfer_content, #update, #update_attribute, #update_attributes, #version, #version=

Methods included from ActiveOrient::BaseProperties

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

Methods inherited from ActiveOrient::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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ModelRecord

Class Method Details

.create(from:, to:, attributes: {}, transaction: false) ⇒ Object

Instantiate a new Edge between two Vertices



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/model/edge.rb', line 21

def create from:, to: , attributes: {}, transaction:  false
return nil if from.blank? || to.blank?
statement = "CREATE EDGE #{ref_name} from #{from.to_or} to #{to.to_or}"
transaction = true if [:fire, :complete, :run].include?(transaction)
ir= db.execute( transaction: transaction ){ statement  }
from.reload! # get last version 
to.is_a?(Array)? to.each( &:reload! )  : to.reload!
ir

  rescue ArgumentError => e
logger.error{ "wrong parameters  #{keyword_arguments} \n\t\t required: from: , to: , attributes:\n\t\t Edge is NOT created"}
end

.delete(where:) ⇒ Object

Fires a “delete edge” command to the database.

The where statement can be empty ( “” or {}“), then all edges are removed

The rid-cache is resetted

:call-seq:
delete where:


44
45
46
47
48
49
# File 'lib/model/edge.rb', line 44

def delete where:  

  db.execute { "delete edge #{ref_name} #{db.compose_where(where)}" }
  reset_rid_store

end

.uniq_indexObject

Establish constrains on Edges

After applying this method Edges are uniq!

Creates individual indices for child-classes if applied to the class itself.



11
12
13
14
15
# File 'lib/model/edge.rb', line 11

def  uniq_index
  create_property  :in,  type: :link, linked_class: :V
  create_property  :out, type: :link, linked_class: :V
  create_index "#{ref_name}_idx", on: [ :in, :out ]
end

Instance Method Details

#removeObject

Removes the actual ActiveOrient::Model-Edge-Object

This method overloads the unspecified ActiveOrient::Model#remove-Method



60
61
62
63
# File 'lib/model/edge.rb', line 60

def remove
# remove works on record-level
  db.delete_edge self
end

#to_humanObject



65
66
67
68
# File 'lib/model/edge.rb', line 65

def to_human
  displayed_attributes =  content_attributes.reject{|k,_| [:in, :out].include?(k) }
  "<#{self.class.to_s.demodulize}[#{rrid}] -i-> ##{ attributes[:in].rid} #{displayed_attributes.to_human} -o-> #{out.rrid}>"
end