Sha256: c9b5f7ccb9b717a17b668c614bafc91b3502103aa8fd9b1d9d54ab32b954074d

Contents?: true

Size: 925 Bytes

Versions: 4

Compression:

Stored size: 925 Bytes

Contents

module Neo4j::ActiveRel
  # A container for ActiveRel's :inbound and :outbound methods. It provides lazy loading of nodes.
  class RelatedNode

    class InvalidParameterError < StandardError
      def message
        'RelatedNode must be initialized with either a node ID or node'
      end
    end

    def initialize(node = nil)
      @node = valid_node_param?(node) ? node : (raise InvalidParameterError.new(self))
    end

    def == (obj)
      loaded if @node.is_a?(Fixnum)
      @node == obj
    end

    def loaded
      @node = @node.respond_to?(:neo_id) ? @node : Neo4j::Node.load(@node)
    end

    def loaded?
      @node.respond_to?(:neo_id)
    end

    def method_missing(*args, &block)
      loaded.send(*args, &block)
    end

    def class
      loaded.send(:class)
    end

    private

    def valid_node_param?(node)
      node.nil? || node.is_a?(Integer) || node.respond_to?(:neo_id)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
neo4j-3.0.0.rc.3 lib/neo4j/active_rel/related_node.rb
neo4j-3.0.0.rc.2 lib/neo4j/active_rel/related_node.rb
neo4j-3.0.0.alpha.11 lib/neo4j/active_rel/related_node.rb
neo4j-3.0.0.alpha.10 lib/neo4j/active_rel/related_node.rb