Class: DemoMode::Persona

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/demo_mode/persona.rb

Defined Under Namespace

Classes: Variant

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/demo_mode/persona.rb', line 9

def name
  @name
end

Instance Method Details

#begin_demo(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/demo_mode/persona.rb', line 30

def begin_demo(&block)
  if block
    @begin_demo = block
  else
    @begin_demo || proc do
       @session.signinable
      redirect_to main_app.root_path
    end
  end
end

#callout(callout = true) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



66
67
68
# File 'lib/demo_mode/persona.rb', line 66

def callout(callout = true) # rubocop:disable Style/OptionalBooleanParameter
  @callout = callout
end

#callout?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/demo_mode/persona.rb', line 70

def callout?
  instance_variable_defined?(:@callout) && @callout
end

#css_classObject



90
91
92
# File 'lib/demo_mode/persona.rb', line 90

def css_class
  "dm-Persona--#{name.to_s.camelize(:lower)}"
end

#custom_sign_in?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/demo_mode/persona.rb', line 86

def custom_sign_in?
  display_credentials? || @begin_demo.present?
end

#display_credentials(display_credentials = true) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



74
75
76
# File 'lib/demo_mode/persona.rb', line 74

def display_credentials(display_credentials = true) # rubocop:disable Style/OptionalBooleanParameter
  @display_credentials = display_credentials
end

#display_credentials?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/demo_mode/persona.rb', line 78

def display_credentials?
  if instance_variable_defined?(:@display_credentials)
    @display_credentials
  else
    DemoMode.display_credentials?
  end
end

#featuresObject



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

def features
  @features ||= []
end

#generate!(variant: :default, password: nil) ⇒ Object



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

def generate!(variant: :default, password: nil)
  variant = variants[variant]
  CleverSequence.reset! if defined?(CleverSequence)
  DemoMode.current_password = password if password
  DemoMode.around_persona_generation.call(variant.signinable_generator)
ensure
  DemoMode.current_password = nil
end

#icon(name_or_path = nil, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/demo_mode/persona.rb', line 14

def icon(name_or_path = nil, &block)
  if block
    @icon = block
  elsif name_or_path
    @path = name_or_path.is_a?(Symbol) ? "demo_mode/icon--#{name_or_path}" : name_or_path
    path = @path
    @icon = ->(_) { image_tag path }
  else
    @icon ||= DemoMode.icon
  end
end

#sign_in_as(&signinable_generator) ⇒ Object



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

def (&signinable_generator)
  variant(:default) do
    (&signinable_generator)
  end
end

#variant(name, &block) ⇒ Object



47
48
49
50
51
# File 'lib/demo_mode/persona.rb', line 47

def variant(name, &block)
  variants[name] = Variant.new(name: name).tap do |v|
    v.instance_eval(&block)
  end
end

#variantsObject



53
54
55
# File 'lib/demo_mode/persona.rb', line 53

def variants
  @variants ||= {}.with_indifferent_access
end