Sha256: 5741977a4dd6f4e487e6dc3d85b965677b6d4c03e4bba156755de324bd1b3f60

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module Neo4jr
  class RelationshipType
    include org.neo4j.api.core.RelationshipType

    @@names = {}

    class << self
      def instance(name)
        return @@names[name] if @@names.include?(name)
        @@names[name] = RelationshipType.new(name)
      end

      def outgoing(type)
        covert_to_relationship_type(Neo4jr::Direction::OUTGOING, type)
      end
      
      def incoming(type)
        covert_to_relationship_type(Neo4jr::Direction::INCOMING, type)
      end
      
      def both(type)
        covert_to_relationship_type(Neo4jr::Direction::BOTH, type)
      end
      
      private
      def covert_to_relationship_type(direction, type)
        [ Neo4jr::RelationshipType.new(type.to_s),
          direction
        ].to_java(:object)
      end
    end

    def to_s
      self.class.to_s + " name='#{@name}'"
    end

    def name
      @name
    end

    private

    def initialize(name)
      @name = name.to_s
      raise ArgumentError.new("Expect type of relationship to be a name of at least one character") if @name.empty?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neo4jr-simple-0.1.3 lib/neo4jr/relationship_type.rb
neo4jr-simple-0.1.0 lib/neo4jr/relationship_type.rb