govuk-wizardry 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de9d24e16cac679c4ee2c36dd8a8556dbe051ffabbfc8771c1dcddd5a00964c3
4
- data.tar.gz: f7bf947d3cbb3e95b03c12d5f527805c1d005d09a6e12738ae7ec77fc4a644df
3
+ metadata.gz: 63518ea4a2c566ad33949be35f38ae906c74a76ccfe1b476733d4b44ef832472
4
+ data.tar.gz: f1841013e966dce14787c53a1968abe29c113da01eab96985cc2a0e1e8bd49c3
5
5
  SHA512:
6
- metadata.gz: 47ac4127a0b74792a27812c48c5911cea6341a7f215714a6b95003443e8237dc70a9ac85129a8b7e88b9e91e98b276cc18fb5a532ef4fcf5e25ec2419967ffa4
7
- data.tar.gz: 98515e090121ce5703f1058190a98ff2d487fa361703bfaefd8578d0c2463621a060ac47b81ba6af566fce3412eac07d4c6ccc62ec0fcc2a03e7f771cef61c07
6
+ metadata.gz: 524640ac8f8c936aaca7be0a3587eb170d451949e394e685e743518b74e040a0954d5ae9b10108f17134c216523675f2c2580a9a246c59fb3cb8065806edf47b
7
+ data.tar.gz: 6ca5e77eb8918d55fbaf68fd017395866f0d7876ed201ecb4d44a2c02091a25e14a18bca3d6bbb8c95d81da36ad74a749d6f2cd87ba4639d0457728ea92f1af7
@@ -62,7 +62,7 @@ private
62
62
  tag.p do
63
63
  [
64
64
  'Add a partial called',
65
- tag.code(%(_completion.html.erb)),
65
+ tag.code(%(_completion_page.html.erb)),
66
66
  'to override this message'
67
67
  ].join(' ').html_safe
68
68
  end
@@ -44,7 +44,7 @@ module Wizardry
44
44
  end
45
45
 
46
46
  def complete?
47
- object.send(framework.completion_flag)
47
+ !!object.send(framework.completion_flag)
48
48
  end
49
49
 
50
50
  private
@@ -1,3 +1,3 @@
1
1
  module Wizardry
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/lib/wizardry.rb CHANGED
@@ -58,7 +58,7 @@ module Wizardry
58
58
  @wizard.current_page.after_update!(@wizard.object)
59
59
  Rails.logger.debug("🧙 Object saved and callbacks run, moving on")
60
60
 
61
- finalize_object if @wizard.complete?
61
+ finish if @wizard.complete?
62
62
  end
63
63
 
64
64
  redirect_to send(@wizard.framework.edit_path_helper, @wizard.next_page.name.to_s.dasherize)
@@ -71,14 +71,22 @@ module Wizardry
71
71
 
72
72
  private
73
73
 
74
- def finalize_object(finalize: :finalize!)
75
- Rails.logger.debug("🧙 Wizard complete, finalizing object")
74
+ def finish
75
+ Rails.logger.debug("🧙 Wizard complete, finishing off")
76
76
 
77
- if @wizard.object.respond_to?(finalize)
78
- @wizard.object.send(finalize)
79
- Rails.logger.debug("🧙 Wizard object finalized")
77
+ finalize_object!
78
+ clear_identifier!
79
+ end
80
+
81
+ def finalize_object!(finalize_method: :finalize!)
82
+ Rails.logger.debug("🧙 Trying to finalize object")
83
+
84
+ if @wizard.object.respond_to?(finalize_method)
85
+ Rails.logger.debug("🧙 Object has #{finalize_method} method - calling it")
86
+
87
+ @wizard.object.send(finalize_method)
80
88
  else
81
- Rails.logger.warn("🧙 Wizard object has no #{finalize} method")
89
+ Rails.logger.warn("🧙 Wizard object has no #{finalize_method} method")
82
90
  end
83
91
  end
84
92
 
@@ -109,7 +117,21 @@ module Wizardry
109
117
  end
110
118
 
111
119
  def identifier
112
- cookies.fetch(wizard.cookie_name) { cookies[wizard.cookie_name] = SecureRandom.uuid }
120
+ cookies.fetch(wizard.cookie_name) { set_identifier! }
121
+ end
122
+
123
+ def set_identifier!
124
+ identifier = SecureRandom.uuid
125
+
126
+ Rails.logger.debug("🧙 Setting cookie #{identifier}")
127
+
128
+ cookies[wizard.cookie_name] = identifier
129
+ end
130
+
131
+ def clear_identifier!
132
+ Rails.logger.debug("🧙 Clearing cookie")
133
+
134
+ cookies.delete(wizard.cookie_name)
113
135
  end
114
136
  end
115
137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-wizardry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-31 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk-components