<commit_before>require 'active_support/inflector'

module RubyCqrs
  module Domain
    class AggregateBase
      attr_reader :aggregate_id, :version, :source_version

    private
      def initialize
        @aggregate_id = Guid.create
        @version = 0
        @source_version = 0
        @event_handler_cache = {}
        @pending_events = []
      end

      def raise_event(event)
        apply(event)
        update_dispatch_detail_for(event)
        @pending_events << event
      end

      def load_from events
        sorted_events = events.sort { |x, y| x.version <=> y.version }
        @aggregate_id = sorted_events[0].aggregate_id
        sorted_events.each do |event|
          apply(event)
          @source_version += 1
        end
      end

      def apply(event)
        dispatch_handler_for(event)
        @version += 1
      end

      def dispatch_handler_for(event)
        target = retrieve_handler_for(event.class)
        self.send(target, event)
      end

      def update_dispatch_detail_for(event)
        event.instance_variable_set(:@aggregate_id, @aggregate_id)
        event.instance_variable_set(:@version, @version)
      end

      def retrieve_handler_for(event_type)
        @event_handler_cache[event_type] ||= begin
          stripped_event_type_name = event_type.to_s.demodulize.underscore
          "on_#{stripped_event_type_name}".to_sym
        end
      end

      def get_changes
        return nil unless @pending_events.size > 0
        { :events => @pending_events,
          :aggregate_id => @aggregate_id,
          :aggregate_type => self.class.name,
          :expecting_source_version => @source_version,
          :expecting_version => @pending_events.max\
          { |a, b| a.version <=> b.version }.version
        }
      end

      def commit
        @pending_events = []
        @source_version = @version
      end
    end
  end
end
<commit_msg>Cleaned up unused error type<commit_after>require 'active_support/inflector'

module RubyCqrs
  module Domain
    class AggregateBase
      attr_reader :aggregate_id, :version, :source_version

    private
      def initialize
        @aggregate_id = Guid.create
        @version = 0
        @source_version = 0
        @event_handler_cache = {}
        @pending_events = []
      end

      def load_from events
        sorted_events = events.sort { |x, y| x.version <=> y.version }
        @aggregate_id = sorted_events[0].aggregate_id
        sorted_events.each do |event|
          apply(event)
          @source_version += 1
        end
      end

      def get_changes
        return nil unless @pending_events.size > 0
        { :events => @pending_events,
          :aggregate_id => @aggregate_id,
          :aggregate_type => self.class.name,
          :expecting_source_version => @source_version,
          :expecting_version => @pending_events.max\
          { |a, b| a.version <=> b.version }.version
        }
      end

      def commit
        @pending_events = []
        @source_version = @version
      end

      def raise_event(event)
        apply(event)
        update_dispatch_detail_for(event)
        @pending_events << event
      end

      def update_dispatch_detail_for(event)
        event.instance_variable_set(:@aggregate_id, @aggregate_id)
        event.instance_variable_set(:@version, @version)
      end

      def apply(event)
        dispatch_handler_for(event)
        @version += 1
      end

      def dispatch_handler_for(event)
        target = retrieve_handler_for(event.class)
        self.send(target, event)
      end

      def retrieve_handler_for(event_type)
        @event_handler_cache[event_type] ||= begin
          stripped_event_type_name = event_type.to_s.demodulize.underscore
          "on_#{stripped_event_type_name}".to_sym
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08391972895491269, 'fraction_numerical': 0.003127443315089914, 'mean_word_length': 2.2117154811715483, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '4539453', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1149, 'n_words': 226}