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
28
29
30
# File 'lib/card/env/location_history.rb', line 23

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
end

#interrupted_actionObject



36
37
38
# File 'lib/card/env/location_history.rb', line 36

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



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

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)

  discard_locations_for card
  location_history.push location_for_history(card)
end