wicked-focused 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -0
- data/VERSION +1 -1
- data/lib/wicked/action.rb +12 -0
- data/lib/wicked/controller/concerns/steps.rb +10 -2
- data/test/dummy/app/controllers/bar_controller.rb +9 -0
- data/wicked-focused.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -155,6 +155,14 @@ In the controller if you find that you want to skip a step, you can do it simply
|
|
155
155
|
|
156
156
|
```ruby
|
157
157
|
|
158
|
+
wicked_base_action do
|
159
|
+
steps :why_us, :subscribe, :login, :payment
|
160
|
+
|
161
|
+
optional_steps: why_us # allow skip
|
162
|
+
command_steps :subscribe, :login, :payment
|
163
|
+
end
|
164
|
+
|
165
|
+
|
158
166
|
show_wizard do
|
159
167
|
wizard do
|
160
168
|
@user = current_user
|
@@ -174,6 +182,22 @@ In the controller if you find that you want to skip a step, you can do it simply
|
|
174
182
|
|
175
183
|
Now you've got a fully functioning AfterSignup controller! If you have questions or if you struggled with something, let me know on [twitter](http://twitter.com/schneems), and i'll try to make it better or make the docs better.
|
176
184
|
|
185
|
+
## Using the Command pattern
|
186
|
+
|
187
|
+
To better encapsulate Business logic, it is recommended for Controllers to create and perform commands. This can fx be done using the [imperator](https://github.com/Agowan/imperator) gem.
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
|
191
|
+
show_wizard do
|
192
|
+
wizard do
|
193
|
+
@user = current_user
|
194
|
+
skip_step if !command_step? step # skip if step not mapped to a command
|
195
|
+
command_for step # execute command of same name as step
|
196
|
+
render_wizard
|
197
|
+
end
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
177
201
|
## Quick Reference
|
178
202
|
|
179
203
|
*Macros*
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/wicked/action.rb
CHANGED
@@ -42,6 +42,18 @@ module Wicked
|
|
42
42
|
@redirect_path
|
43
43
|
end
|
44
44
|
|
45
|
+
def command_for name
|
46
|
+
command! name if command_step?(name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def command_step? name
|
50
|
+
command_steps.include? name.to_sym
|
51
|
+
end
|
52
|
+
|
53
|
+
def command_steps
|
54
|
+
@command_steps ||= self.class.superclass.command_steps
|
55
|
+
end
|
56
|
+
|
45
57
|
def wizard_redirect
|
46
58
|
redirect_to @redirect_path if @redirect_path
|
47
59
|
end
|
@@ -44,7 +44,7 @@ module Wicked::Controller::Concerns::Steps
|
|
44
44
|
end
|
45
45
|
|
46
46
|
module ClassMethods
|
47
|
-
attr_reader :wizard_steps, :skip_steps
|
47
|
+
attr_reader :wizard_steps, :skip_steps, :command_steps
|
48
48
|
|
49
49
|
def steps(*args)
|
50
50
|
options = args.last.is_a?(Hash) ? callbacks.pop : {}
|
@@ -59,6 +59,11 @@ module Wicked::Controller::Concerns::Steps
|
|
59
59
|
@skip_steps = args
|
60
60
|
end
|
61
61
|
alias :optional_steps :allow_skip_for
|
62
|
+
|
63
|
+
def command_steps(*args)
|
64
|
+
return @command_steps if args.empty?
|
65
|
+
@command_steps = args
|
66
|
+
end
|
62
67
|
end
|
63
68
|
|
64
69
|
def steps=(wizard_steps)
|
@@ -73,11 +78,14 @@ module Wicked::Controller::Concerns::Steps
|
|
73
78
|
|
74
79
|
def skip_step?
|
75
80
|
return false unless params[:skip_step]
|
76
|
-
skip_steps = self.class.superclass.skip_steps
|
77
81
|
return true if skip_steps.blank?
|
78
82
|
skip_steps.include? step.to_sym
|
79
83
|
end
|
80
84
|
|
85
|
+
def skip_steps
|
86
|
+
@skip_steps ||= self.class.superclass.skip_steps
|
87
|
+
end
|
88
|
+
|
81
89
|
def previous_step(current_step = nil)
|
82
90
|
return previous_step if current_step == nil
|
83
91
|
index = steps.index(current_step)
|
@@ -5,17 +5,26 @@ module BarController
|
|
5
5
|
|
6
6
|
wicked_base_action do
|
7
7
|
steps :first, :second, :last_step
|
8
|
+
|
9
|
+
command_steps :first
|
8
10
|
end
|
9
11
|
|
10
12
|
wizard_action :show do
|
11
13
|
wizard do
|
12
14
|
# skip_step if skip_step?
|
15
|
+
command_for step # should be in update!
|
16
|
+
|
13
17
|
render_wizard
|
14
18
|
end
|
19
|
+
|
20
|
+
def command! name
|
21
|
+
puts "execute command: #{name}"
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
wizard_action :update do
|
18
26
|
wizard do
|
27
|
+
command_for step
|
19
28
|
# update code here!
|
20
29
|
render_wizard
|
21
30
|
end
|
data/wicked-focused.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wicked-focused
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -254,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
segments:
|
256
256
|
- 0
|
257
|
-
hash:
|
257
|
+
hash: 234203573561291092
|
258
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
259
|
none: false
|
260
260
|
requirements:
|