Sha256: 50dd67950b2e39383e1cd15569c4fdd16e6d830794552a98b2f30b84274051ab

Contents?: true

Size: 662 Bytes

Versions: 8

Compression:

Stored size: 662 Bytes

Contents

module ServiceController::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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rails-add_ons-3.0.0.pre1 app/concerns/service_controller/location_history.rb
rails-add_ons-2.2.1 app/concerns/service_controller/location_history.rb
rails-add_ons-2.2.0 app/concerns/service_controller/location_history.rb
rails-add_ons-2.1.1 app/concerns/service_controller/location_history.rb
rails-add_ons-2.1.0 app/concerns/service_controller/location_history.rb
rails-add_ons-2.0.2 app/concerns/service_controller/location_history.rb
rails-add_ons-2.0.1 app/concerns/service_controller/location_history.rb
rails-add_ons-2.0.0 app/concerns/service_controller/location_history.rb