class E

Public Class Methods

connect(dir= "-" , **args) click to toggle source
# 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: {}) click to toggle source

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

# 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.expand  # 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: click to toggle source

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
# 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) click to toggle source
# File lib/model/e.rb, line 2
def self.naming_convention name=nil
    name.present? ? name.upcase : ref_name.upcase
end
uniq_index() click to toggle source

Establish constrains on Edges

After applying this method Edges are uniq!

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

# 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

Public Instance Methods

delete() click to toggle source

Deletes the actual ActiveOrient::Model-Edge-Object

# File lib/model/edge.rb, line 106
def delete
        db.execute{ "delete edge #{ref_name} #{rrid}" }
end
to_human() click to toggle source
# 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