demo_mode 1.3.0 → 1.4.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: 4bd782c3af4723645221a5df708ba1acde6e07a0d6d875f8644f201db1b19e02
4
- data.tar.gz: 45fc4c48119fd8af020ec131243431178436c5ae247339a0fd9c9e3602bf4f2a
3
+ metadata.gz: e75a91ac2a0b995cd5fbcfa34904c1307aa0c6c92fcab77f1a688736d7c0b5c9
4
+ data.tar.gz: 9bf6279af73413607cbc11be096f1859310bf215dcd1f09282aab198f9519866
5
5
  SHA512:
6
- metadata.gz: 7fcc0016139912a257d9e507abc30c0c2c63771483f2573372d40b6bcf553cedd9d9c2041b636f9d06a7265e7af22a55b3f6192aaf11d5be33f43cf01432d654
7
- data.tar.gz: 16503560feaa837f466bf8dd05307175ac715847250012d43c29f75f54b7ad1e1eeb7afec0fce008ed2c8e4ed1457e05a76bb7e4725317726b081dfdbf6586ed
6
+ metadata.gz: 03554b83a0d69bcac5b4ace0a246468b6235f112aa5df2491e33622ee1538877edecab2d185a16611b9305741d3cccc7d1d8ea579089a0c87cf50b505ba2094b
7
+ data.tar.gz: 286eef0bd8b57736f4388d85bd0aaf7847f63d9cde752c90513f45ca03f5f67d080a49fe2ce02f1cbc522ba6b1c6520bdd82256c3e5e6cd350944d785122e588
@@ -25,7 +25,7 @@ module DemoMode
25
25
 
26
26
  def create
27
27
  @session = Session.new(create_params)
28
- @session.save_and_generate_account!
28
+ @session.save_and_generate_account_later!(**options_params.to_unsafe_h.deep_symbolize_keys)
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 }
@@ -77,5 +77,9 @@ module DemoMode
77
77
  def create_params
78
78
  params.require(:session).permit(:persona_name, :variant)
79
79
  end
80
+
81
+ def options_params
82
+ params.fetch(:options, {}).permit!
83
+ end
80
84
  end
81
85
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  module DemoMode
4
4
  class AccountGenerationJob < DemoMode.base_job_name.constantize
5
- def perform(session)
5
+ def perform(session, **options)
6
6
  session.with_lock do
7
7
  persona = session.persona
8
8
  raise "Unknown persona: #{session.persona_name}" if persona.blank?
9
9
 
10
- signinable = persona.generate!(variant: session.variant, password: session.signinable_password)
10
+ signinable = persona.generate!(variant: session.variant, password: session.signinable_password, options: options)
11
11
  session.update!(signinable: signinable)
12
12
  end
13
13
  raise "Failed to create signinable persona!" if session.signinable.blank?
@@ -25,10 +25,17 @@ module DemoMode
25
25
  DemoMode.personas.find { |p| p.name.to_s == persona_name.to_s }
26
26
  end
27
27
 
28
- def save_and_generate_account!
28
+ def save_and_generate_account!(**options)
29
29
  transaction do
30
30
  save!
31
- AccountGenerationJob.perform_later(self)
31
+ AccountGenerationJob.perform_now(self, **options)
32
+ end
33
+ end
34
+
35
+ def save_and_generate_account_later!(**options)
36
+ transaction do
37
+ save!
38
+ AccountGenerationJob.perform_later(self, **options)
32
39
  end
33
40
  end
34
41
 
data/lib/demo_mode/cli.rb CHANGED
@@ -20,8 +20,8 @@ class DemoMode::Cli
20
20
  prompt_persona
21
21
  end
22
22
 
23
- def created_personas
24
- @created_personas ||= []
23
+ def created_sessions
24
+ @created_sessions ||= []
25
25
  end
26
26
 
27
27
  private
@@ -41,23 +41,24 @@ class DemoMode::Cli
41
41
  CLI::UI::Frame.open("{{*}} Generate an Account! {{*}}") do
42
42
  CLI::UI::Prompt.ask('Which persona should we use?') do |handler|
43
43
  DemoMode.personas.sort_by { |p| p.name.to_s }.each do |persona|
44
- persona_name = persona.name.to_s.titleize
44
+ persona_label = persona.name.to_s.titleize
45
45
 
46
- handler.option(persona_name) do
46
+ handler.option(persona_label) do
47
47
  persona.features.each do |feature|
48
48
  puts "👉 #{feature}"
49
49
  end
50
50
 
51
51
  named_tags = SemanticLogger.named_tags if defined?(SemanticLogger)
52
52
 
53
- variant = variant_for(persona, persona_name)
53
+ variant = variant_for(persona, persona_label)
54
54
 
55
55
  CLI::UI::Spinner.spin("generating account...") do |spinner|
56
56
  SemanticLogger.push_named_tags(named_tags) if defined?(SemanticLogger)
57
- password = DemoMode.current_password
58
- signinable = persona.generate!(variant: variant)
57
+
58
+ session = DemoMode::Session.new(persona_name: persona.name, variant: variant)
59
+ session.save_and_generate_account!
59
60
  spinner.update_title('done!')
60
- created_personas << { name: persona_name, email: signinable.email, password: password }
61
+ created_sessions << session
61
62
  end
62
63
  end
63
64
  end
@@ -67,22 +68,23 @@ class DemoMode::Cli
67
68
  ask_next_step
68
69
  end
69
70
 
70
- def variant_for(persona, persona_name)
71
+ def variant_for(persona, persona_label)
71
72
  if persona.variants.keys == ['default']
72
73
  :default
73
74
  else
74
75
  CLI::UI::Prompt.ask(
75
- "Which variant should we use for #{persona_name}?",
76
+ "Which variant should we use for #{persona_label}?",
76
77
  options: persona.variants.keys,
77
78
  )
78
79
  end
79
80
  end
80
81
 
81
82
  def display_personas
82
- created_personas.each do |persona|
83
- CLI::UI::Frame.open("{{*}} #{persona[:name]} {{*}}") do
84
- puts "👤 :: #{persona[:email]}"
85
- puts "🔑 :: #{persona[:password]}"
83
+ created_sessions.each do |session|
84
+ CLI::UI::Frame.open("{{*}} #{session.persona_name} {{*}}") do
85
+ puts "👤 :: #{session.signinable.email}"
86
+ puts "🔑 :: #{session.signinable_password}"
87
+ puts "🌐 :: #{DemoMode.session_url(session)}"
86
88
  end
87
89
  end
88
90
  end
@@ -54,11 +54,11 @@ module DemoMode
54
54
  @variants ||= {}.with_indifferent_access
55
55
  end
56
56
 
57
- def generate!(variant: :default, password: nil)
57
+ def generate!(variant: :default, password: nil, options: {})
58
58
  variant = variants[variant]
59
59
  CleverSequence.reset! if defined?(CleverSequence)
60
60
  DemoMode.current_password = password if password
61
- DemoMode.around_persona_generation.call(variant.signinable_generator)
61
+ DemoMode.around_persona_generation.call(variant.signinable_generator, **options)
62
62
  ensure
63
63
  DemoMode.current_password = nil
64
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DemoMode
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.1'
5
5
  end
data/lib/demo_mode.rb CHANGED
@@ -46,6 +46,16 @@ module DemoMode
46
46
  Thread.current[:_demo_mode_password] = value
47
47
  end
48
48
 
49
+ def session_url(session)
50
+ routes = DemoMode::Engine.routes
51
+
52
+ options = routes.default_url_options.presence
53
+ options ||= ActionMailer::Base.default_url_options.presence if defined?(ActionMailer::Base)
54
+ options ||= { only_path: true }
55
+
56
+ routes.url_for(controller: 'demo_mode/sessions', action: 'show', id: session, **options)
57
+ end
58
+
49
59
  private
50
60
 
51
61
  def configuration
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.3.0
4
+ version: 1.4.1
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-22 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-ui