demo_mode 1.2.3 → 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: 3032c631c3d2308b21588fe6d8598635c3a90e0be15edaae81fe9d869bd9b089
4
- data.tar.gz: 8af75b0ceeb37fcdd98120980c3ab2ac14a18e6b503c04fbf8e3fd9eb6b47c48
3
+ metadata.gz: 4bd782c3af4723645221a5df708ba1acde6e07a0d6d875f8644f201db1b19e02
4
+ data.tar.gz: 45fc4c48119fd8af020ec131243431178436c5ae247339a0fd9c9e3602bf4f2a
5
5
  SHA512:
6
- metadata.gz: 7d5352ef735cc354a3da6260c690a1862c4e24f1adca8e91b7a8ba13944e0a1000339d3f184a8ea12b97e6578f535a040c24b17254f0c8d3cfe9131182a8d1fa
7
- data.tar.gz: 810e15296241a0913d4c2a194eeae7577c7c6cbad58f5bc28c188fff2279eefc134368aa17e2fe14813db925192c8e1f2f1ddd88ddc9044cee92136429d93345
6
+ metadata.gz: 7fcc0016139912a257d9e507abc30c0c2c63771483f2573372d40b6bcf553cedd9d9c2041b636f9d06a7265e7af22a55b3f6192aaf11d5be33f43cf01432d654
7
+ data.tar.gz: 16503560feaa837f466bf8dd05307175ac715847250012d43c29f75f54b7ad1e1eeb7afec0fce008ed2c8e4ed1457e05a76bb7e4725317726b081dfdbf6586ed
@@ -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.3'
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.3
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-07-10 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