<commit_before>module Neo4j
  module Rails
    module Relationships

      class NodesDSL #:nodoc:
        include Enumerable

        def initialize(storage, dir)
          @storage = storage
          @dir = dir
        end

        def build(attrs)
          self << (node = @storage.build(attrs))
          node
        end

        def create(attrs)
          self << (node = @storage.create(attrs))
          node.save
          node
        end

        def create!(attrs)
          self << (node = @storage.create(attrs))
          node.save!
          node
        end

        def <<(other)
          @storage.create_relationship_to(other, @dir)
          self
        end

        def depth(d)
          adapt_to_traverser.depth(d)
        end

        def adapt_to_traverser
          Neo4j::Traversal::Traverser.new(@storage.node, @storage.rel_type, @dir)
        end

        def [](index)
          i = 0
          each{|x| return x if i == index; i += 1}
          nil # out of index
        end

        def is_a?(type)
          # ActionView requires this for nested attributes to work
          return true if Array == type
          super
        end

        def find(*args, &block)
          return super(*args, &block) if block
          node = args.first
          enum = Enumerator.new(@storage, :each_rel, @dir)
          if @dir == :incoming
            enum.find{|r| r.start_node == node}
          else
            enum.find{|r| r.end_node == node}
          end
        end

        def destroy_all<commit_msg>Made object.collection.find() return a node instead of a relationship.<commit_after>module Neo4j
  module Rails
    module Relationships

      class NodesDSL #:nodoc:
        include Enumerable

        def initialize(storage, dir)
          @storage = storage
          @dir = dir
        end

        def build(attrs)
          self << (node = @storage.build(attrs))
          node
        end

        def create(attrs)
          self << (node = @storage.create(attrs))
          node.save
          node
        end

        def create!(attrs)
          self << (node = @storage.create(attrs))
          node.save!
          node
        end

        def <<(other)
          @storage.create_relationship_to(other, @dir)
          self
        end

        def depth(d)
          adapt_to_traverser.depth(d)
        end

        def adapt_to_traverser
          Neo4j::Traversal::Traverser.new(@storage.node, @storage.rel_type, @dir)
        end

        def [](index)
          i = 0
          each{|x| return x if i == index; i += 1}
          nil # out of index
        end

        def is_a?(type)
          # ActionView requires this for nested attributes to work
          return true if Array == type
          super
        end

        def find(*args, &block)
          return super(*args, &block) if block
          node = args.first
          enum = Enumerator.new(@storage, :each_node, @dir).find{|n| n == node}

          #if @dir == :incoming
          #  enum.find{|r| r.start_node == node}
          #else
          #  enum.find{|r| r.end_node == node}
          #end
        end

        def destroy_all
{'fraction_non_alphanumeric': 0.09450063211125158, 'fraction_numerical': 0.0025284450063211127, 'mean_word_length': 1.4477958236658932, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3857693', 'n_tokens_mistral': 936, 'n_tokens_neox': 888, 'n_words': 249}