Sha256: 4e834c8fcf27a0d2661416218ccc85a0d57a5b742b756ae9df134ef8094321f2

Contents?: true

Size: 1.42 KB

Versions: 60

Compression:

Stored size: 1.42 KB

Contents

module Neo4j
  module ActiveNode
    module Unpersisted
      # The values in this Hash are returned and used outside by reference
      # so any modifications to the Array should be in-place
      def deferred_create_cache
        @deferred_create_cache ||= {}
      end

      def defer_create(association_name, object, options = {})
        clear_deferred_nodes_for_association(association_name) if options[:clear]

        deferred_nodes_for_association(association_name) << object
      end

      def deferred_nodes_for_association(association_name)
        deferred_create_cache[association_name.to_sym] ||= []
      end

      def pending_deferred_creations?
        !deferred_create_cache.values.all?(&:empty?)
      end

      def clear_deferred_nodes_for_association(association_name)
        deferred_nodes_for_association(association_name.to_sym).clear
      end

      private

      def process_unpersisted_nodes!
        deferred_create_cache.each do |association_name, nodes|
          association_proxy = association_proxy(association_name)

          nodes.each do |node|
            if node.respond_to?(:changed?)
              node.save if node.changed? || !node.persisted?
              fail "Unable to defer node persistence, could not save #{node.inspect}" unless node.persisted?
            end

            association_proxy << node
          end
        end

        @deferred_create_cache = {}
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 2 rubygems

Version Path
neo4j-7.0.13 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.12 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.11 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.10 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.9 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.8 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.7 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.6 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.5 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.4 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.3 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.2 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.1 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0.rc.7 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0.rc.6 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0.rc.5 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0.rc.4 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0.rc.3 lib/neo4j/active_node/unpersisted.rb
neo4j-7.0.0.rc.2 lib/neo4j/active_node/unpersisted.rb