Sha256: f203d90da8ab8d8718d63274bda7aaf603375ced47b0996307409082b5f9c2e2

Contents?: true

Size: 734 Bytes

Versions: 49

Compression:

Stored size: 734 Bytes

Contents

module Rao
  module ServiceController::LocationHistoryConcern
    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
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
rao-service_controller-0.0.10.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.9.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.8.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.7.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.6.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.5.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.4.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.3.pre app/concerns/rao/service_controller/location_history_concern.rb
rao-service_controller-0.0.2.pre app/concerns/rao/service_controller/location_history_concern.rb