Module: SimpleWorkflow::Detour

Included in:
Controller, Helper, Middleware
Defined in:
lib/simple_workflow/detour.rb

Overview

Utility methods to manage the breadcrumb history

Instance Method Summary collapse

Instance Method Details

#pop_detour(session, origin_options = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/simple_workflow/detour.rb', line 21

def pop_detour(session, origin_options = nil)
  detours = session[:detours]
  return nil unless detours

  detour = detours.delete(origin_options) || detours.pop
  Rails.logger.debug { "popped detour: #{detour.inspect} #{session[:detours].size} more" }
  reset_workflow(session) if detours.empty?
  detour
end

#reset_workflow(session) ⇒ Object



31
32
33
# File 'lib/simple_workflow/detour.rb', line 31

def reset_workflow(session)
  session.delete(:detours)
end

#store_detour_in_session(session, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_workflow/detour.rb', line 5

def store_detour_in_session(session, options)
  if session[:detours]
    if session[:detours].last == options
      Rails.logger.try(:debug, "Ignored duplicate detour: #{options.inspect}")
      return
    end
    if session[:detours].delete(options)
      Rails.logger.try(:debug, "Deleted duplicate detour: #{options.inspect}")
    end
  else
    session[:detours] = []
  end
  session[:detours] << options
  Rails.logger.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
end