Sha256: cf5395b73ba58c870bfb7bf8a7ce0453fe6e87e52d78c0589085c6331f7dfa00

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

module Arcade
  class Edge  <  Base
   # schema schema.strict    #  -- throws an error if  specified keys are missing
    attribute :in, Types::Rid
    attribute :out, Types::Rid

    def accepted_methods
      super + [ :vertices, :in, :out, :inV, :outV ]
    end
    #
    # Add Contrains to the edge
    # CREATE INDEX Watched_out_in ON <edge type«  (`@out`, `@in`) UNIQUE
    #
    def self.create  from:, to:, **attr
        db.create_edge  database_name, from: from, to: to, **attr
    rescue Arcade::QueryError => e
      if  e.message =~ /Duplicated key\s+.+\sfound on index/
        if e.args.keys.first == :exceptionArgs
          # return the  previously assigned edge
          e.args[:exceptionArgs].split('|').last.load_rid
        else
          raise
        end
      else
        raise
       end

    end

    def delete
      db.execute{  "delete edge #{ rid }" }.select_result
    end
    ## gets the adjacent Vertex
    def inV
      query( projection: "inV()").query.select_result
    end
    def outV
      query( projection: "outV()").query.select_result
    end
    def vertices in_or_out = nil
  case in_or_out
      when :in
        inV
      when :out
        outV
      else
        [inV, outV]
      end
    end

    alias bothV vertices


    def to_human
      "<#{self.class.to_s.snake_case}[#{rid}] :.: #{ out }->#{invariant_attributes}->#{ attributes[:in] }>"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arcadedb-0.5.0 lib/model/edge.rb