Sha256: 770ee22605ab7b8043934814c580918f0e63231b4bfd0dd8f3625b15bc4a8143

Contents?: true

Size: 1.67 KB

Versions: 64

Compression:

Stored size: 1.67 KB

Contents

module Neo4j
  module Shared
    module Callbacks #:nodoc:
      extend ActiveSupport::Concern

      module ClassMethods
        include ActiveModel::Callbacks
      end

      included do
        include ActiveModel::Validations::Callbacks
        # after_find is triggered by the `find` method defined in lib/neo4j/active_node/id_property.rb
        define_model_callbacks :initialize, :find, only: :after
        define_model_callbacks :save, :create, :update, :destroy, :touch
      end

      def initialize(args = nil)
        run_callbacks(:initialize) { super }
      end

      def destroy #:nodoc:
        tx = Neo4j::Transaction.new
        run_callbacks(:destroy) { super }
      rescue
        @_deleted = false
        @attributes = @attributes.dup
        tx.mark_failed
        raise
      ensure
        tx.close if tx
      end

      def touch #:nodoc:
        run_callbacks(:touch) { super }
      end

      # Allows you to perform a callback if a condition is not satisfied.
      # @param [Symbol] kind The callback type to execute unless the guard is true
      # @param [TrueClass,FalseClass] guard When this value is true, the block is yielded without executing callbacks.
      def conditional_callback(kind, guard)
        return yield if guard
        run_callbacks(kind) { yield }
      end

      private

      def create_or_update #:nodoc:
        run_callbacks(:save) { super }
      end

      def create_model #:nodoc:
        Neo4j::Transaction.run do
          run_callbacks(:create) { super }
        end
      end

      def update_model(*) #:nodoc:
        Neo4j::Transaction.run do
          run_callbacks(:update) { super }
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 2 rubygems

Version Path
neo4j-7.2.3 lib/neo4j/shared/callbacks.rb
neo4j-7.2.2 lib/neo4j/shared/callbacks.rb
neo4j-7.1.4 lib/neo4j/shared/callbacks.rb
neo4j-7.0.16 lib/neo4j/shared/callbacks.rb
neo4j-7.2.1 lib/neo4j/shared/callbacks.rb
neo4j_legacy-7.2.0.2 lib/neo4j/shared/callbacks.rb
neo4j_legacy-7.2.0.1 lib/neo4j/shared/callbacks.rb
neo4j-7.2.0 lib/neo4j/shared/callbacks.rb
neo4j-7.1.3 lib/neo4j/shared/callbacks.rb
neo4j-7.0.15 lib/neo4j/shared/callbacks.rb
neo4j-7.1.2 lib/neo4j/shared/callbacks.rb
neo4j-7.1.1 lib/neo4j/shared/callbacks.rb
neo4j-7.1.0 lib/neo4j/shared/callbacks.rb
neo4j-7.0.14 lib/neo4j/shared/callbacks.rb
neo4j-7.0.13 lib/neo4j/shared/callbacks.rb
neo4j-7.0.12 lib/neo4j/shared/callbacks.rb
neo4j-7.0.11 lib/neo4j/shared/callbacks.rb
neo4j-7.0.10 lib/neo4j/shared/callbacks.rb
neo4j-7.0.9 lib/neo4j/shared/callbacks.rb
neo4j-7.0.8 lib/neo4j/shared/callbacks.rb