<commit_before>module Tire
  module Model

    module Callbacks

      def self.included(base)
        if base.respond_to?(:after_save) && base.respond_to?(:after_destroy)
          base.send :after_save,    lambda { tire.update_index }
          base.send :after_destroy, lambda { tire.update_index }
        end

        if base.respond_to?(:before_destroy) && !base.instance_methods.map(&:to_sym).include?(:destroyed?)
          base.class_eval do
            before_destroy  { @destroyed = true }
            def destroyed?; !!@destroyed; end
          end
        end

        base.class_eval do
          define_model_callbacks(:update_elasticsearch_index, :only => [:after, :before])
        end if base.respond_to?(:define_model_callbacks)
      end

    end

  end
end<commit_msg>[DOC] Added RDoc annotations for the Tire::Model::Callbacks module<commit_after>module Tire
  module Model

    # Main module containing the infrastructure for automatic updating
    # of the _ElasticSearch_ index on model instance create, update or delete.
    #
    # Include it in your model: `include Tire::Model::Callbacks`
    #
    # The model must respond to `after_save` and `after_destroy` callbacks
    # (ActiveModel and ActiveRecord models do so, by default).
    #
    # By including the model, you will also have the `after_update_elasticsearch_index` and
    # `before_update_elasticsearch_index` callbacks available.
    # 
    module Callbacks

      # A hook triggered by the `include Tire::Model::Callbacks` statement in the model.
      #
      def self.included(base)

        # Update index on model instance change or destroy.
        #
        if base.respond_to?(:after_save) && base.respond_to?(:after_destroy)
          base.send :after_save,    lambda { tire.update_index }
          base.send :after_destroy, lambda { tire.update_index }
        end

        # Add neccessary infrastructure for the model, when missing in
        # some half-baked ActiveModel implementations.
        #
        if base.respond_to?(:before_destroy) && !base.instance_methods.map(&:to_sym).include?(:destroyed?)
          base.class_eval do
            before_destroy  { @destroyed = true }
            def destroyed?; !!@destroyed; end
          end
        end

        # Define _Tire's_ callbacks.
        #
        base.class_eval do
          define_model_callbacks(:update_elasticsearch_index, :only => [:after, :before])
        end if base.respond_to?(:define_model_callbacks)
      end

    end

  end
end
{'fraction_non_alphanumeric': 0.0874751491053678, 'fraction_numerical': 0.0, 'mean_word_length': 2.6253602305475505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7029446', 'n_tokens_mistral': 723, 'n_tokens_neox': 705, 'n_words': 192}