demo_mode 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/demo_mode/demoable.rb +8 -1
- data/app/controllers/demo_mode/sessions_controller.rb +1 -1
- data/app/jobs/demo_mode/account_generation_job.rb +1 -7
- data/app/models/demo_mode/session.rb +13 -6
- data/lib/demo_mode/cli.rb +2 -2
- 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: 4bd782c3af4723645221a5df708ba1acde6e07a0d6d875f8644f201db1b19e02
|
4
|
+
data.tar.gz: 45fc4c48119fd8af020ec131243431178436c5ae247339a0fd9c9e3602bf4f2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fcc0016139912a257d9e507abc30c0c2c63771483f2573372d40b6bcf553cedd9d9c2041b636f9d06a7265e7af22a55b3f6192aaf11d5be33f43cf01432d654
|
7
|
+
data.tar.gz: 16503560feaa837f466bf8dd05307175ac715847250012d43c29f75f54b7ad1e1eeb7afec0fce008ed2c8e4ed1457e05a76bb7e4725317726b081dfdbf6586ed
|
@@ -12,7 +12,14 @@ module DemoMode
|
|
12
12
|
def current_demo_session
|
13
13
|
if session.key?(:demo_session)
|
14
14
|
@current_demo_session = nil if @current_demo_session&.id != session[:demo_session]['id']
|
15
|
-
@current_demo_session ||= Session.
|
15
|
+
@current_demo_session ||= Session.find_by(id: session[:demo_session]['id'])
|
16
|
+
|
17
|
+
if @current_demo_session.nil?
|
18
|
+
session.delete(:demo_session)
|
19
|
+
sign_out
|
20
|
+
end
|
21
|
+
|
22
|
+
@current_demo_session
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
@@ -25,7 +25,7 @@ module DemoMode
|
|
25
25
|
|
26
26
|
def create
|
27
27
|
@session = Session.new(create_params)
|
28
|
-
@session.
|
28
|
+
@session.save_and_generate_account!
|
29
29
|
session[:demo_session] = { 'id' => @session.id, 'last_request_at' => Time.zone.now }
|
30
30
|
respond_to do |f|
|
31
31
|
f.html { redirect_to @session }
|
@@ -4,7 +4,7 @@ module DemoMode
|
|
4
4
|
class AccountGenerationJob < DemoMode.base_job_name.constantize
|
5
5
|
def perform(session)
|
6
6
|
session.with_lock do
|
7
|
-
persona = persona
|
7
|
+
persona = session.persona
|
8
8
|
raise "Unknown persona: #{session.persona_name}" if persona.blank?
|
9
9
|
|
10
10
|
signinable = persona.generate!(variant: session.variant, password: session.signinable_password)
|
@@ -12,11 +12,5 @@ module DemoMode
|
|
12
12
|
end
|
13
13
|
raise "Failed to create signinable persona!" if session.signinable.blank?
|
14
14
|
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def persona(session)
|
19
|
-
DemoMode.personas.find { |p| p.name.to_s == session.persona_name.to_s }
|
20
|
-
end
|
21
15
|
end
|
22
16
|
end
|
@@ -5,10 +5,10 @@ module DemoMode
|
|
5
5
|
attribute :variant, default: :default
|
6
6
|
|
7
7
|
validates :persona_name, :variant, presence: true
|
8
|
+
validates :persona, presence: { message: :required }, on: :create, if: :persona_name?
|
8
9
|
belongs_to :signinable, polymorphic: true, optional: true
|
9
10
|
|
10
11
|
before_create :set_password!
|
11
|
-
after_create -> { AccountGenerationJob.perform_later(self) }
|
12
12
|
|
13
13
|
delegate :begin_demo,
|
14
14
|
:custom_sign_in?,
|
@@ -20,15 +20,22 @@ module DemoMode
|
|
20
20
|
signinable.public_send(DemoMode.signinable_username_method)
|
21
21
|
end
|
22
22
|
|
23
|
+
# Heads up: finding a persona is not guaranteed (e.g. past sessions)
|
24
|
+
def persona
|
25
|
+
DemoMode.personas.find { |p| p.name.to_s == persona_name.to_s }
|
26
|
+
end
|
27
|
+
|
28
|
+
def save_and_generate_account!
|
29
|
+
transaction do
|
30
|
+
save!
|
31
|
+
AccountGenerationJob.perform_later(self)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
23
35
|
private
|
24
36
|
|
25
37
|
def set_password!
|
26
38
|
self.signinable_password ||= DemoMode.current_password
|
27
39
|
end
|
28
|
-
|
29
|
-
# Heads up: finding a persona is not guaranteed (e.g. past sessions)
|
30
|
-
def persona
|
31
|
-
DemoMode.personas.find { |p| p.name.to_s == persona_name.to_s }
|
32
|
-
end
|
33
40
|
end
|
34
41
|
end
|
data/lib/demo_mode/cli.rb
CHANGED
@@ -48,12 +48,12 @@ class DemoMode::Cli
|
|
48
48
|
puts "👉 #{feature}"
|
49
49
|
end
|
50
50
|
|
51
|
-
named_tags = SemanticLogger.named_tags
|
51
|
+
named_tags = SemanticLogger.named_tags if defined?(SemanticLogger)
|
52
52
|
|
53
53
|
variant = variant_for(persona, persona_name)
|
54
54
|
|
55
55
|
CLI::UI::Spinner.spin("generating account...") do |spinner|
|
56
|
-
SemanticLogger.push_named_tags(named_tags)
|
56
|
+
SemanticLogger.push_named_tags(named_tags) if defined?(SemanticLogger)
|
57
57
|
password = DemoMode.current_password
|
58
58
|
signinable = persona.generate!(variant: variant)
|
59
59
|
spinner.update_title('done!')
|
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: 1.
|
4
|
+
version: 1.3.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: 2024-
|
11
|
+
date: 2024-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cli-ui
|