Module: Card::Env::LocationHistory

Included in:
Card::Env
Defined in:
lib/card/env.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#discard_locations_for(card) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/card/env.rb', line 91

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

#interrupted_actionObject



105
106
107
# File 'lib/card/env.rb', line 105

def interrupted_action
  session.delete :interrupted_action
end

#location_historyObject

include Card::Location



71
72
73
74
75
# File 'lib/card/env.rb', line 71

def location_history
  session[:history] ||= [Card::Location.card_path('')]
  session[:history].shift if session[:history].size > 5
  session[:history]
end

#previous_locationObject



86
87
88
89
# File 'lib/card/env.rb', line 86

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

#save_interrupted_action(uri) ⇒ Object



101
102
103
# File 'lib/card/env.rb', line 101

def save_interrupted_action uri
  session[:interrupted_action] = uri
end

#save_location(card) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/card/env.rb', line 77

def save_location card
  return if Env.ajax? || !Env.html? || !card.known? ||
            (card.codename == 'signin')
  discard_locations_for card
  session[:previous_location] =
    Card::Location.card_path card.cardname.url_key
  location_history.push previous_location
end

#url_key_for_location(location) ⇒ Object



109
110
111
# File 'lib/card/env.rb', line 109

def url_key_for_location(location)
  location.match( /\/([^\/]*$)/ ) ? $1 : nil
end