simple_workflow 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_workflow/controller.rb +23 -13
- data/lib/simple_workflow/helper.rb +2 -2
- data/lib/simple_workflow/version.rb +1 -1
- metadata +4 -4
@@ -4,28 +4,36 @@ module SimpleWorkflow::Controller
|
|
4
4
|
store_detour(params)
|
5
5
|
redirect_to(options)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def rjs_detour_to(options)
|
9
9
|
store_detour(params, request.post?)
|
10
10
|
rjs_redirect_to(options)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def rjs_redirect_to(options)
|
14
14
|
@options = options
|
15
15
|
render :template => 'redirect', :layout => false, :formats => :js
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def store_detour(options, post = false)
|
19
19
|
options[:request_method] = :post if post
|
20
20
|
if session[:detours] && session[:detours].last == options
|
21
|
-
logger.debug "duplicate detour: #{options.inspect}"
|
21
|
+
logger.debug "Ignored duplicate detour: #{options.inspect}"
|
22
22
|
return
|
23
23
|
end
|
24
|
-
logger.debug "adding detour: #{options.inspect}"
|
25
24
|
session[:detours] ||= []
|
26
25
|
session[:detours] << options
|
26
|
+
ss = ws = nil
|
27
|
+
loop do
|
28
|
+
ss = ActiveSupport::Base64.encode64(Marshal.dump(session.to_hash)).size
|
29
|
+
ws = ActiveSupport::Base64.encode64(Marshal.dump(session[:detours])).size
|
30
|
+
break unless ws >= 2048 || (ss >= 3072 && session[:detours].size > 0)
|
31
|
+
logger.info "Workflow too large (#{ws}). Dropping oldest detour."
|
32
|
+
session[:detours].shift
|
33
|
+
end
|
34
|
+
logger.debug "Added detour: #{options.inspect}, session: #{ss} bytes, workflow(#{session[:detours].size}): #{ws} bytes"
|
27
35
|
end
|
28
|
-
|
36
|
+
|
29
37
|
def store_detour_from_params
|
30
38
|
if params[:detour]
|
31
39
|
store_detour(params[:detour])
|
@@ -34,7 +42,7 @@ module SimpleWorkflow::Controller
|
|
34
42
|
pop_detour
|
35
43
|
end
|
36
44
|
end
|
37
|
-
|
45
|
+
|
38
46
|
def back
|
39
47
|
return false if session[:detours].nil?
|
40
48
|
detour = pop_detour
|
@@ -46,22 +54,24 @@ module SimpleWorkflow::Controller
|
|
46
54
|
end
|
47
55
|
true
|
48
56
|
end
|
49
|
-
|
57
|
+
|
50
58
|
def back_or_redirect_to(*options)
|
51
59
|
back or redirect_to(*options)
|
52
60
|
end
|
53
|
-
|
61
|
+
|
54
62
|
def pop_detour
|
55
63
|
detours = session[:detours]
|
56
64
|
return nil unless detours
|
57
65
|
detour = detours.pop
|
58
66
|
logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more"
|
59
|
-
if detours.empty?
|
60
|
-
session[:detours] = nil
|
61
|
-
end
|
67
|
+
reset_workflow if detours.empty?
|
62
68
|
detour
|
63
69
|
end
|
64
70
|
|
71
|
+
def reset_workflow
|
72
|
+
session.delete(:detours)
|
73
|
+
end
|
74
|
+
|
65
75
|
def redirect_to_post(options)
|
66
76
|
url = url_for options
|
67
77
|
render :text => <<EOF, :layout => false
|
@@ -73,5 +83,5 @@ module SimpleWorkflow::Controller
|
|
73
83
|
</html>
|
74
84
|
EOF
|
75
85
|
end
|
76
|
-
|
86
|
+
|
77
87
|
end
|
@@ -49,13 +49,13 @@ module SimpleWorkflow::Helper
|
|
49
49
|
not session[:detours].nil?
|
50
50
|
end
|
51
51
|
|
52
|
-
def back_or_link_to(title, options = nil)
|
52
|
+
def back_or_link_to(title, options = nil, html_options = nil)
|
53
53
|
if session[:detours]
|
54
54
|
options = {:return_from_detour => true}.update(session[:detours].last)
|
55
55
|
options[:id] ||= nil
|
56
56
|
logger.debug "linked return from detour: #{options.inspect}"
|
57
57
|
end
|
58
|
-
link_to(title, options) if options
|
58
|
+
link_to(title, options, html_options) if options
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Uwe Kubosch
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-31 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|