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
- #discard_locations_for(card) ⇒ Object
- #interrupted_action ⇒ Object
-
#location_history ⇒ Object
include Card::Location.
- #previous_location ⇒ Object
- #save_interrupted_action(uri) ⇒ Object
- #save_location(card) ⇒ Object
- #url_key_for_location(location) ⇒ Object
Instance Method Details
#discard_locations_for(card) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/card/env.rb', line 88 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_action ⇒ Object
102 103 104 |
# File 'lib/card/env.rb', line 102 def interrupted_action session.delete :interrupted_action end |
#location_history ⇒ Object
include Card::Location
68 69 70 71 72 73 74 75 |
# File 'lib/card/env.rb', line 68 def location_history #warn "sess #{session.class}, #{session.object_id}" session[:history] ||= [Card::Location.card_path('')] if session[:history] session[:history].shift if session[:history].size > 5 session[:history] end end |
#previous_location ⇒ Object
84 85 86 |
# File 'lib/card/env.rb', line 84 def previous_location session[:previous_location] ||= location_history.last if location_history end |
#save_interrupted_action(uri) ⇒ Object
98 99 100 |
# File 'lib/card/env.rb', line 98 def save_interrupted_action uri session[:interrupted_action] = uri end |
#save_location(card) ⇒ Object
77 78 79 80 81 82 |
# 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
106 107 108 |
# File 'lib/card/env.rb', line 106 def url_key_for_location(location) location.match( /\/([^\/]*$)/ ) ? $1 : nil end |