Module: DemoMode

Defined in:
lib/demo_mode.rb,
lib/demo_mode/config.rb,
lib/demo_mode/engine.rb,
lib/demo_mode/persona.rb,
lib/demo_mode/version.rb,
app/models/demo_mode/session.rb,
lib/demo_mode/factory_bot_ext.rb,
app/jobs/demo_mode/account_generation_job.rb,
lib/generators/demo_mode/install_generator.rb,
app/controllers/concerns/demo_mode/demoable.rb,
app/controllers/demo_mode/sessions_controller.rb,
app/controllers/demo_mode/application_controller.rb

Defined Under Namespace

Modules: Clis, Demoable, FactoryBotExt, FactoryBotRunnerExt Classes: AccountGenerationJob, ApplicationController, Cli, Config, Engine, InstallGenerator, Persona, Session, SessionsController

Constant Summary collapse

ICONS =
{
  tophat: "/demo_mode/assets/icon--tophat.png?v=#{VERSION}",
  user: "/demo_mode/assets/icon--user.png?v=#{VERSION}",
  users: "/demo_mode/assets/icon--users.png?v=#{VERSION}",
}.freeze
VERSION =
'3.3.0'

Class Method Summary collapse

Class Method Details

.add_persona(name = default_name) ⇒ Object



34
35
36
# File 'lib/demo_mode.rb', line 34

def add_persona(name = default_name, &)
  configuration.persona(name, &)
end

.callout_personasObject



38
39
40
# File 'lib/demo_mode.rb', line 38

def callout_personas
  personas.select(&:callout?)
end

.configureObject



30
31
32
# File 'lib/demo_mode.rb', line 30

def configure(&)
  configuration.instance_eval(&)
end

.current_passwordObject



46
47
48
# File 'lib/demo_mode.rb', line 46

def current_password
  Thread.current[:_demo_mode_password] ||= password.call
end

.current_password=(value) ⇒ Object



50
51
52
# File 'lib/demo_mode.rb', line 50

def current_password=(value)
  Thread.current[:_demo_mode_password] = value
end

.enabled?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/demo_mode.rb', line 20

def enabled?
  ActiveModel::Type::Boolean::FALSE_VALUES.exclude?(ENV.fetch('DEMO_MODE', 'false')).tap do |enabled|
    webvalve_check! if enabled && defined?(WebValve)
  end
end

.session_url(session) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/demo_mode.rb', line 54

def session_url(session)
  Rails.application.reload_routes_unless_loaded if Rails.gem_version >= Gem::Version.new('8.0')

  routes = DemoMode::Engine.routes

  options = routes.default_url_options.presence
  options ||= ActionMailer::Base.default_url_options.presence if defined?(ActionMailer::Base)
  options ||= { only_path: true }

  routes.url_for(controller: 'demo_mode/sessions', action: 'show', id: session, **options)
end

.standard_personasObject



42
43
44
# File 'lib/demo_mode.rb', line 42

def standard_personas
  personas - callout_personas
end

.table_name_prefixObject



26
27
28
# File 'lib/demo_mode.rb', line 26

def table_name_prefix
  'demo_mode_'
end