Sha256: 20ddb1be9f81350fd69e0904fdf21a6b6485f388914bec0acd139333e5159014

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

module Cadet
  class Node
    attr_accessor :underlying

    def initialize(node)
      @underlying = node
    end

    def add_label(label)
      @underlying.addLabel(DynamicLabel.label(label))
      self
    end
    def labels
      @underlying.getLabels().map(&:name)
    end

    def []= (property, value)
      @underlying.setProperty(property.to_java_string, value)
    end

    def [] (property)
      @underlying.getProperty(property.to_java_string)
    end

    def each_relationship(direction, type)
      @underlying.getRelationships(Directions[direction], DynamicRelationshipType.withName(type)).each do |rel|
        yield Relationship.new(rel)
      end
    end

    def create_outgoing(to, type)
      Relationship.new @underlying.createRelationshipTo(to.underlying, DynamicRelationshipType.withName(type))
    end
    def outgoing(type)
      NodeTraverser.new(self, :outgoing, type)
    end
    def incoming(type)
      NodeTraverser.new(self, :incoming, type)
    end

    def outgoing_rels(type)
      NodeRelationships.new(self, :outgoing, type)
    end
    def incoming_rels(type)
      NodeRelationships.new(self, :incoming, type)
    end

    def == other_node
      @underlying.getId == other_node.underlying.getId
    end

    def method_missing(name, *args, &block)
      case name
        when /([A-z_]*)_to$/
          self.class.class_eval "
            def #{name}(value)
              create_outgoing(value, :#{$1})
            end
          "
          self.send(name, *args, &block)
        else
          raise NotImplementedError
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cadet-0.1.4-java lib/cadet/node.rb
cadet-0.1.3-java lib/cadet/node.rb
cadet-0.1.2-java lib/cadet/node.rb
cadet-0.1.1-java lib/cadet/node.rb