Sha256: 46e3f2fa63f075877532c9be24c430699f2c067d6b60a6cb6c9b1abd4c1d8f9e

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

class E  < ActiveOrient::Model
  ## class methods
  class << self
=begin
Establish constrains on Edges

After applying this method Edges are uniq!

Creates individual indices for child-classes if applied to the class itself.
=end
  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

=begin
 Instantiate a new Edge between two Vertices 

=end
  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

=begin
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: 
=end
  def delete where:  

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

  end
  
	end   # class methods

	###  instance methods  ###

=begin
Removes the actual ActiveOrient::Model-Edge-Object

This method overloads the unspecified ActiveOrient::Model#remove-Method
=end
  def remove
  # remove works on record-level
    db.delete_edge self
  end

	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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active-orient-0.79 lib/model/edge.rb