<commit_before>module ResourcesController::LocationHistory
  extend ActiveSupport::Concern

  included do
    if respond_to?(:before_action)
      before_action :store_location
    else
      before_filter :store_location
    end
  end

  private

  def store_location
    truncate_location_history(9)
    location_history[Time.zone.now] = request.referer
  end

  def location_history
    session[:location_history] ||= {}
  end

  def last_location
    location_history.sort.last.try(:last)
  end

  def truncate_location_history(count = 0)
    return if location_history.size <= count
    session[:location_history] = session[:location_history].sort.last(count).to_h
  end
end<commit_msg>Fix truncating in ResourcesController::LocationHistory.<commit_after>module ResourcesController::LocationHistory
  extend ActiveSupport::Concern

  included do
    if respond_to?(:before_action)
      before_action :store_location
    else
      before_filter :store_location
    end
  end

  private

  def store_location
    truncate_location_history(9)
    location_history[Time.zone.now] = request.referer
  end

  def location_history
    session[:location_history] ||= {}
  end

  def last_location
    location_history.sort.last.try(:last)
  end

  def truncate_location_history(count = 0)
    return if location_history.size <= count
    truncated = session[:location_history].sort.last(count)
    session[:location_history] = if truncated.respond_to?(:to_h)
      truncated.to_h
    else
      truncated.each_with_object({}) { |a, hash| hash[a.first] = a.last }
    end
  end
end
{'fraction_non_alphanumeric': 0.08233058898036733, 'fraction_numerical': 0.00253324889170361, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2886625', 'n_tokens_mistral': 487, 'n_tokens_neox': 471, 'n_words': 95}