Sha256: 7aa15ab2baeefbcf5705fa56c69e3d178593a08bce451c907f20678e181889da

Contents?: true

Size: 1.04 KB

Versions: 38

Compression:

Stored size: 1.04 KB

Contents

module Rao
  module ResourcesController::LocationHistoryConcern
    extend ActiveSupport::Concern

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

      helper_method :last_location
    end

    private

    def store_location
      return if request.referer.nil?
      truncate_location_history(9)
      logger.debug "[LocationHistoryConcern] Storing last location [#{request.referer}]"
      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
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
rao-resources_controller-0.0.50.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.49.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.48.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.47.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.46.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.45.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.44.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.43.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.42.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.41.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.40.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.39.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.38.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.37.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.36.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.35.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.34.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.33.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.32.pre app/concerns/rao/resources_controller/location_history_concern.rb
rao-resources_controller-0.0.31.pre app/concerns/rao/resources_controller/location_history_concern.rb