Module: Card::Env::LocationHistory

Included in:
Card::Env
Defined in:
lib/card/env/location_history.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



23
24
25
26
27
# File 'lib/card/env/location_history.rb', line 23

def discard_locations_for card
  session[:history] = location_history.reject do |l|
    location_cardname(l) == card.name
  end.compact
end

#interrupted_actionObject



33
34
35
# File 'lib/card/env/location_history.rb', line 33

def interrupted_action
  session.delete :interrupted_action
end

#location_historyObject



6
7
8
9
10
# File 'lib/card/env/location_history.rb', line 6

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

#previous_locationObject



19
20
21
# File 'lib/card/env/location_history.rb', line 19

def previous_location
  location_history&.last
end

#save_interrupted_action(uri) ⇒ Object



29
30
31
# File 'lib/card/env/location_history.rb', line 29

def save_interrupted_action uri
  session[:interrupted_action] = uri
end

#save_location(card) ⇒ Object



12
13
14
15
16
17
# File 'lib/card/env/location_history.rb', line 12

def save_location card
  return unless save_location? card

  location = request ? request.original_url : location_for_history(card)
  location_history.push(location).uniq!
end