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



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

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

Instance Method Details

#around_persona_generation(&block) ⇒ Object



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

def around_persona_generation(&block)
  if block
    @around_persona_generation = block
  else
    @around_persona_generation ||= ->(generator, options = {}) { generator.call(options) }
  end
end

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



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/demo_mode/config.rb', line 56

def icon(name_or_path = nil, &block)
  if block
    @icon = block
  elsif name_or_path
    @path = ICONS.fetch(name_or_path, name_or_path)
  else
    @path ||= ICONS.fetch(:user)
    path = @path
    @icon ||= ->(_) { image_tag path }
  end
end

#loader(&block) ⇒ Object



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

def loader(&block)
  if block
    @loader = block
  else
    @loader ||= ->(_) { image_tag("/demo_mode/assets/loader.png?v=#{VERSION}") }
  end
end

#logo(&block) ⇒ Object



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

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

#password(&block) ⇒ Object



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

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



106
107
108
109
110
111
# File 'lib/demo_mode/config.rb', line 106

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

#personasObject



113
114
115
116
117
118
119
# File 'lib/demo_mode/config.rb', line 113

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

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



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

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



98
99
100
101
102
103
104
# File 'lib/demo_mode/config.rb', line 98

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

#stylesheetsObject



33
34
35
36
37
38
# File 'lib/demo_mode/config.rb', line 33

def stylesheets
  @stylesheets ||= [
    "/demo_mode/assets/vendor/normalize-v8.0.1.css",
    "/demo_mode/assets/demo_mode.css?v=#{VERSION}",
  ]
end