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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e781b6e2b4017d8efb8260570397d61579e8dd03d553bbe720f7964dae74bb53
4
- data.tar.gz: 9a1e6e3af03b1155dc9bc059d1366afb35ae1ef1a6aabe2caf86e8802eeea9d5
3
+ metadata.gz: 4bd782c3af4723645221a5df708ba1acde6e07a0d6d875f8644f201db1b19e02
4
+ data.tar.gz: 45fc4c48119fd8af020ec131243431178436c5ae247339a0fd9c9e3602bf4f2a
5
5
  SHA512:
6
- metadata.gz: a976ad663436a8b25d20ffca633b400fb1bcd36acb62f669122159d70e4aefdc97b4c2ea6fef4f9af0135c8f55eee6456e606342acac70fd23baa799bd90d71c
7
- data.tar.gz: 88aa9c77999969cbad123ba5fdf36b4c4d92320c05833f502ec4cbc6e6a02179a6d591ae3d33463a10e1d7112c31ec957578ea65b8f19d8ff7b29c0c24c34f8e
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.find(session[:demo_session]['id'])
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.save!
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(session)
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!')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DemoMode
4
- VERSION = '1.2.2'
4
+ VERSION = '1.3.0'
5
5
  end
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.2.2
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-06-13 00:00:00.000000000 Z
11
+ date: 2024-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-ui