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



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

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

Instance Method Details

#around_persona_generation(&block) ⇒ Object



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

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



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

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



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

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

#logo(&block) ⇒ Object



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

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

#password(&block) ⇒ Object



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

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



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

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

#personasObject



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

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

#sign_in_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_in_path = block
  elsif @sign_in_path
    ctx.instance_eval(&@sign_in_path)
  end
end

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



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

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

#stylesheetsObject



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

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