Class: DemoMode::Config

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/demo_mode/config.rb

Constant Summary collapse

WORDS =
%w(area book business case child company country day eye fact family government group home job life lot money month night number
office people phone place point problem program question right room school state story student study system thing time water
way week word work world year).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_nameObject



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

def self.app_name
  Rails.application.class.module_parent.name
end

Instance Method Details

#around_persona_generation(&block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/demo_mode/config.rb', line 72

def around_persona_generation(&block)
  if block
    @around_persona_generation = block
  else
    @around_persona_generation ||= :call.to_proc
  end
end

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/demo_mode/config.rb', line 46

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
  else
    @path ||= 'demo_mode/icon--user'
    path = @path
    @icon ||= ->(_) { image_tag path }
  end
end

#loader(&block) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/demo_mode/config.rb', line 38

def loader(&block)
  if block
    @loader = block
  else
    @loader ||= ->(_) { image_tag('demo_mode/loader.png') }
  end
end

#logo(&block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/demo_mode/config.rb', line 30

def (&block)
  if block
    @logo = block
  else
    @logo ||= ->(_) { (:strong, DemoMode::Config.app_name) }
  end
end

#password(&block) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/demo_mode/config.rb', line 62

def password(&block)
  if block
    @password = block
  else
    @password ||= -> {
      "#{WORDS.sample}#{WORDS.sample.upcase}#{WORDS.sample}!#{Array.new(2) { rand(10).to_s }.join}"
    }
  end
end

#persona(persona_name, &block) ⇒ Object



96
97
98
99
100
101
# File 'lib/demo_mode/config.rb', line 96

def persona(persona_name, &block)
  personas << Persona.new(name: persona_name).tap do |p|
    p.instance_eval(&block)
    p.validate!
  end
end

#personasObject



103
104
105
106
107
108
109
# File 'lib/demo_mode/config.rb', line 103

def personas
  unless instance_variable_defined?(:@personas)
    @personas = []
    auto_load_personas!
  end
  @personas
end

#sign_in_path(ctx = nil, &block) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/demo_mode/config.rb', line 80

def (ctx = nil, &block)
  if block
    @sign_in_path = block
  elsif @sign_in_path
    ctx.instance_eval(&@sign_in_path)
  end
end

#sign_up_path(ctx = nil, &block) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/demo_mode/config.rb', line 88

def (ctx = nil, &block)
  if block
    @sign_up_path = block
  elsif @sign_up_path
    ctx.instance_eval(&@sign_up_path)
  end
end