Sha256: 992e1d25f5ce2f4d3d70518ebaa865675cf61d299febbf14cb47e9bb7bac03c3

Contents?: true

Size: 1.53 KB

Versions: 29

Compression:

Stored size: 1.53 KB

Contents

class Card
  module Env
    # session history helpers: we keep a history stack so that in the case of
    # card removal we can crawl back up to the last un-removed location
    module LocationHistory
      def location_history
        session[:history] ||= [Env::Location.card_path("")]
        session[:history].shift if session[:history].size > 5
        session[:history]
      end

      def save_location card
        return unless save_location?(card)
        discard_locations_for card
        session[:previous_location] =
          Env::Location.card_path card.name.url_key
        location_history.push previous_location
      end

      def save_location? card
        !Env.ajax? && Env.html? && card.known? && (card.codename != :signin)
      end

      def previous_location
        return unless location_history
        session[:previous_location] ||= location_history.last
      end

      def discard_locations_for card
        # quoting necessary because cards have things like "+*" in the names..
        session[:history] = location_history.reject do |loc|
          if (url_key = url_key_for_location(loc))
            url_key.to_name.key == card.key
          end
        end.compact
        session[:previous_location] = nil
      end

      def save_interrupted_action uri
        session[:interrupted_action] = uri
      end

      def interrupted_action
        session.delete :interrupted_action
      end

      def url_key_for_location location
        (%r{/([^/]*$)} =~ location) ? Regexp.last_match[1] : nil
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
card-1.96.8 lib/card/env/location_history.rb
card-1.96.7 lib/card/env/location_history.rb
card-1.96.6 lib/card/env/location_history.rb
card-1.96.5 lib/card/env/location_history.rb
card-1.96.4 lib/card/env/location_history.rb
card-1.96.3 lib/card/env/location_history.rb
card-1.96.2 lib/card/env/location_history.rb
card-1.96.1 lib/card/env/location_history.rb
card-1.96.0 lib/card/env/location_history.rb
card-1.95.3 lib/card/env/location_history.rb
card-1.95.2 lib/card/env/location_history.rb
card-1.95.1 lib/card/env/location_history.rb
card-1.95.0 lib/card/env/location_history.rb
card-1.94.1 lib/card/env/location_history.rb
card-1.94.0 lib/card/env/location_history.rb
card-1.93.13 lib/card/env/location_history.rb
card-1.93.12 lib/card/env/location_history.rb
card-1.93.11 lib/card/env/location_history.rb
card-1.93.10 lib/card/env/location_history.rb
card-1.93.9 lib/card/env/location_history.rb