demo_mode 3.7.2 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/jobs/demo_mode/account_generation_job.rb +7 -1
- data/app/models/demo_mode/session.rb +28 -4
- data/lib/demo_mode/persona.rb +15 -0
- data/lib/demo_mode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b39607da6e06571e9a6b0d57b9efa1ab59f4109836e5c87776892fa30e239f95
|
|
4
|
+
data.tar.gz: 86c5e89834dff8123aa4b22f15d883d63eaa3209fc6d3236a261d625f98de2b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31b38ae765035a33cd107ea2340ce33c5875880102248c8bf269b55244aee007ca960c54c3ec79edd6a4a8b6e862811297b5ce4cd2c77c54bca07b620ad8ce41
|
|
7
|
+
data.tar.gz: f016a43e1afa88f64119ca71b548cd0a4c7bb4d07c5d2fb2bc57830508f26fcb6138fc13e4c7dddf9a3383a402457ed1cadc870b14e6b0055696ae91fb064290
|
|
@@ -9,8 +9,14 @@ module DemoMode
|
|
|
9
9
|
raise "Unknown persona: #{session.persona_name}" if persona.blank?
|
|
10
10
|
|
|
11
11
|
signinable = persona.generate!(variant: session.variant, password: session.signinable_password, options: options)
|
|
12
|
+
session.update!(signinable: signinable, persona_checksum: persona.file_checksum)
|
|
13
|
+
|
|
14
|
+
if session.claimed_at?
|
|
15
|
+
persona.effective_at_claim_callback(session.variant)&.call(signinable)
|
|
16
|
+
end
|
|
17
|
+
|
|
12
18
|
new_status = session.claimed_at? ? 'in_use' : 'available'
|
|
13
|
-
session.update!(
|
|
19
|
+
session.update!(status: new_status)
|
|
14
20
|
end
|
|
15
21
|
rescue StandardError => e
|
|
16
22
|
session.update!(status: 'failed')
|
|
@@ -14,7 +14,7 @@ module DemoMode
|
|
|
14
14
|
state 'processing', default: true, from: 'failed'
|
|
15
15
|
state 'available', from: 'processing'
|
|
16
16
|
state 'in_use', from: %w(processing available)
|
|
17
|
-
state 'failed', from:
|
|
17
|
+
state 'failed', from: %w(processing available)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
scope :unclaimed, -> { where(claimed_at: nil) }
|
|
@@ -56,13 +56,15 @@ module DemoMode
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def self.claim_for(persona_name:, variant: DEFAULT_VARIANT, **generation_opts)
|
|
59
|
+
persona = DemoMode.personas.find { |p| p.name.to_s == persona_name.to_s && p.variants.key?(variant) }
|
|
59
60
|
pool_hit = false
|
|
60
61
|
session = transaction do
|
|
61
62
|
existing = available_for(persona_name, variant).lock.first
|
|
62
63
|
pool_hit = existing.present?
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if existing
|
|
65
|
+
claim_pool_session(existing, persona, variant)
|
|
66
|
+
else
|
|
67
|
+
new_claimed_session(persona_name, variant, generation_opts)
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
70
|
ActiveSupport::Notifications.instrument('demo_mode.session.claimed',
|
|
@@ -70,6 +72,28 @@ module DemoMode
|
|
|
70
72
|
session
|
|
71
73
|
end
|
|
72
74
|
|
|
75
|
+
class << self
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def claim_pool_session(session, persona, variant)
|
|
79
|
+
transaction(requires_new: true) do
|
|
80
|
+
persona&.effective_at_claim_callback(variant)&.call(session.signinable)
|
|
81
|
+
session.claim!
|
|
82
|
+
rescue StandardError
|
|
83
|
+
raise ActiveRecord::Rollback
|
|
84
|
+
end
|
|
85
|
+
session.update!(status: 'failed') unless session.claimed_at?
|
|
86
|
+
session
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def new_claimed_session(persona_name, variant, generation_opts)
|
|
90
|
+
new(persona_name: persona_name, variant: variant).tap do |s|
|
|
91
|
+
s.claim!
|
|
92
|
+
AccountGenerationJob.perform_later(s, **generation_opts) if s.signinable.blank?
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
73
97
|
def claim!
|
|
74
98
|
if new_record?
|
|
75
99
|
self.claimed_at = Time.zone.now
|
data/lib/demo_mode/persona.rb
CHANGED
|
@@ -97,6 +97,16 @@ module DemoMode
|
|
|
97
97
|
@enabled_condition ? @enabled_condition.call : true
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
+
def at_claim(&block)
|
|
101
|
+
@at_claim_callback = block
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
attr_reader :at_claim_callback
|
|
105
|
+
|
|
106
|
+
def effective_at_claim_callback(variant_name)
|
|
107
|
+
variants[variant_name]&.at_claim_callback || @at_claim_callback
|
|
108
|
+
end
|
|
109
|
+
|
|
100
110
|
def callout(callout = true) # rubocop:disable Style/OptionalBooleanParameter
|
|
101
111
|
@callout = callout
|
|
102
112
|
end
|
|
@@ -154,10 +164,15 @@ module DemoMode
|
|
|
154
164
|
@enabled_condition ? @enabled_condition.call : true
|
|
155
165
|
end
|
|
156
166
|
|
|
167
|
+
def at_claim(&block)
|
|
168
|
+
@at_claim_callback = block
|
|
169
|
+
end
|
|
170
|
+
|
|
157
171
|
def title
|
|
158
172
|
name.is_a?(Symbol) ? name.to_s.titleize : name.to_s
|
|
159
173
|
end
|
|
160
174
|
|
|
175
|
+
attr_reader :at_claim_callback
|
|
161
176
|
attr_reader :signinable_generator
|
|
162
177
|
end
|
|
163
178
|
end
|
data/lib/demo_mode/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: demo_mode
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Griffith
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|