Class: E
- Defined in:
- lib/model/e.rb,
lib/model/edge.rb
Overview
< ActiveOrient::Model
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
Attributes inherited from ActiveOrient::Base
Class Method Summary collapse
-
.connect(dir = "-", **args) ⇒ Object
arguments: direction: :both,.
-
.create(from:, to:, set: {}, transaction: false, update_cache: false, **attributes) ⇒ Object
Instantiate a new Edge between two Vertices .
-
.delete(where:) ⇒ Object
Fires a “delete edge” command to the database.
- .naming_convention(name = nil) ⇒ Object
-
.uniq_index ⇒ Object
Establish constrains on Edges.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the actual ActiveOrient::Model-Edge-Object.
- #to_human ⇒ Object
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
Methods included from ModelClass
#add_edge_link, #all, #alter_property, #classname, #count, #create, #create_class, #create_index, #create_properties, #create_property, #delete_property, #delete_record, #delete_records, #first, #get, #get_records, #indexes, #last, #link_list, #migrate_property, #namespace_prefix, #naming_convention, #orientdb_class, #print_properties, #properties, #query, #query_database, #require_model_file, #update, #update!, #upsert, #where
Methods included from OrientSupport::Support
#as, #compose_where, #generate_sql_list, #where, #while_s
Methods included from ModelRecord
classname, #find, #from_orient, #has_property?, #is_edge?, #method_missing, #properties, #query, #reload!, #rid, #rrid, #save, #to_or, #to_s, #transfer_content, #update, #update_attribute, #update_attributes, #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
Methods included from Conversions
#to_key, #to_param, #to_partial_path
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
.connect(dir = "-", **args) ⇒ Object
arguments: direction: :both,
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/model/edge.rb', line 77 def connect dir= "-" , **args # arguments: direction: :both, # count: 1, # # as: nil direction = case dir when "-" :both when '->' :out when '<-' :in when Symbol dir end args[:direction] ||= direction OrientSupport::MatchConnection.new self, **args end |
.create(from:, to:, set: {}, transaction: false, update_cache: false, **attributes) ⇒ Object
Instantiate a new Edge between two Vertices
Properties can be placed using the :set-directive or simply by adding key: value- parameter-pairs
if the creation of an edged is not possible, due to constrains (uniq_index), the already
connecting edge is returned
the method is thread safe, if transaction and update_cache are set to false
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/model/edge.rb', line 31 def create from:, to: , set: {}, transaction: false, update_cache: false, **attributes return nil if from.blank? || to.blank? set.merge!(attributes) content = set.empty? ? "" : "content #{set.to_orient.to_json}" statement = "CREATE EDGE #{ref_name} from #{from.to_or} to #{to.to_or} #{content}" transaction = true if [:fire, :complete, :run].include?(transaction) ir= db.execute( transaction: transaction, process_error: false ){ statement } if update_cache from.reload! # get last version to.is_a?(Array)? to.each( &:reload! ) : to.reload! end to.is_a?(Array) ? ir : ir.first # return the plain edge, if only one is created rescue RestClient::InternalServerError => e sentence= JSON.parse( e.response)['errors'].last['content'] if sentence =~ /found duplicated key/ ref_rid = sentence.split.last. # return expanded rid else raise end 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
to_do: Implement :all=> true directive
support from: , to: syntax
:call-seq:
delete where:
69 70 71 72 73 74 |
# File 'lib/model/edge.rb', line 69 def delete where: db.execute { "delete edge #{ref_name} #{db.compose_where(where)}" } reset_rid_store end |
.naming_convention(name = nil) ⇒ Object
2 3 4 |
# File 'lib/model/e.rb', line 2 def self.naming_convention name=nil name.present? ? name.upcase : ref_name.upcase end |
.uniq_index ⇒ Object
Establish constrains on Edges
After applying this method Edges are uniq!
Creates individual indices for child-classes if applied to the class itself.
15 16 17 18 19 |
# File 'lib/model/edge.rb', line 15 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
#delete ⇒ Object
Deletes the actual ActiveOrient::Model-Edge-Object
106 107 108 |
# File 'lib/model/edge.rb', line 106 def delete db.execute{ "delete edge #{ref_name} #{rrid}" } end |
#to_human ⇒ Object
109 110 111 112 |
# File 'lib/model/edge.rb', line 109 def to_human displayed_attributes = attributes.reject{|k,_| [:in, :out].include?(k) } "<#{self.class.to_s.demodulize}[#{rrid}] :.: #{ attributes[:out].rid}->#{displayed_attributes.to_human}->#{attributes[:in].rid}>" end |