<commit_before>module AASM
  class InstanceBase

    def initialize(instance)
      @instance = instance
    end

    def current_state
      @current_state ||= persistable? ? @instance.aasm_read_state : enter_initial_state
    end

    def current_state=(state)
      if @instance.respond_to?(:aasm_write_state_without_persistence) || @instance.private_methods.include?('aasm_write_state_without_persistence')
        @instance.aasm_write_state_without_persistence(state)
      end
      @current_state = state
    end

    def enter_initial_state
      state_name = determine_state_name(@instance.class.aasm_initial_state)
      state_object = state_object_for_name(state_name)

      state_object.fire_callbacks(:before_enter, @instance)
      state_object.fire_callbacks(:enter, @instance)
      self.current_state = state_name
      state_object.fire_callbacks(:after_enter, @instance)

      state_name
    end

    def human_state
      AASM::Localizer.new.human_state_name(@instance.class, current_state)
    end

    def events(state=current_state)
      events = @instance.class.aasm_events.values.select {|e| e.transitions_from_state?(state) }
      events.map {|e| e.name}
    end

    # filters the results of events_for_current_state so that only those that
    # are really currently possible (given transition guards) are shown.
    # TODO: what about events.permissible ?
    def permissible_events
      events.select{ |e| @instance.send(("may_" + e.to_s + "?").to_sym) }
    end

    def state_object_for_name(name)
      obj = @instance.class.aasm.states.find {|s| s == name}
      raise AASM::UndefinedState, "State :#{name} doesn't exist" if obj.nil?
      obj
    end

    def determine_state_name(state)
      case state<commit_msg>it's more a question up to now<commit_after>module AASM
  class InstanceBase

    def initialize(instance)
      @instance = instance
    end

    def current_state
      @current_state ||= persistable? ? @instance.aasm_read_state : enter_initial_state
    end

    def current_state=(state)
      if @instance.respond_to?(:aasm_write_state_without_persistence) || @instance.private_methods.include?('aasm_write_state_without_persistence')
        @instance.aasm_write_state_without_persistence(state)
      end
      @current_state = state
    end

    def enter_initial_state
      state_name = determine_state_name(@instance.class.aasm_initial_state)
      state_object = state_object_for_name(state_name)

      state_object.fire_callbacks(:before_enter, @instance)
      state_object.fire_callbacks(:enter, @instance)
      self.current_state = state_name
      state_object.fire_callbacks(:after_enter, @instance)

      state_name
    end

    def human_state
      AASM::Localizer.new.human_state_name(@instance.class, current_state)
    end

    def events(state=current_state)
      events = @instance.class.aasm_events.values.select {|e| e.transitions_from_state?(state) }
      events.map {|e| e.name}
    end

    # filters the results of events_for_current_state so that only those that
    # are really currently possible (given transition guards) are shown.
    # QUESTION: what about events.permissible ?
    def permissible_events
      events.select{ |e| @instance.send(("may_" + e.to_s + "?").to_sym) }
    end

    def state_object_for_name(name)
      obj = @instance.class.aasm.states.find {|s| s == name}
      raise AASM::UndefinedState, "State :#{name} doesn't exist" if obj.nil?
      obj
    end

    def determine_state_name(state)
      case state
{'fraction_non_alphanumeric': 0.09029153693744693, 'fraction_numerical': 0.0, 'mean_word_length': 3.5955786736020805, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1649944', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1091, 'n_words': 223}