Module: InvokeGenerators

Included in:
MenuGenerator
Defined in:
lib/generators/invoke_generators.rb

Constant Summary collapse

GENERATOR_CLASSES =

Generator class lookup cache — avoids repeated Object.const_get string interpolation

Hash.new { |h, k| h[k] = Object.const_get("#{k}Generator") }

Class Method Summary collapse

Class Method Details

.add_generator(generators, *gens) ⇒ Object



28
29
30
# File 'lib/generators/invoke_generators.rb', line 28

def add_generator(generators, *gens)
  gens.each { |generator| generators.push generator }
end

.collect_flags(structure) ⇒ Object



45
46
47
48
49
# File 'lib/generators/invoke_generators.rb', line 45

def collect_flags(structure)
  flags = []
  flags << 'axe_addon' if structure[:accessibility] && !mobile_automation?(structure[:automation])
  flags
end

.generate_framework(structure = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/invoke_generators.rb', line 11

def generate_framework(structure = {})
  generators = %w[Automation Common Helpers]
  framework = structure[:framework]
  add_generator(generators, framework.capitalize)
  add_generator(generators, 'Github')
  extra_args = collect_flags(structure)
  generators.each do |generator|
    invoke_generator({
                       automation: structure[:automation],
                       framework:,
                       generator:,
                       name: structure[:name],
                       extra_args:
                     })
  end
end

.invoke_generator(structure = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/generators/invoke_generators.rb', line 35

def invoke_generator(structure = {})
  args = [structure[:automation], structure[:framework], structure[:name]]
  args.concat(structure[:extra_args] || [])
  generator_class = GENERATOR_CLASSES[structure[:generator]]
  generator = generator_class.new(args)
  # Enable batch mode on the template cache to skip mtime checks during generation
  generator.class.template_renderer.batch_mode = true if generator.class.respond_to?(:template_renderer)
  generator.invoke_all
end

.mobile_automation?(automation) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/generators/invoke_generators.rb', line 51

def mobile_automation?(automation)
  %w[ios android cross_platform].include?(automation)
end

.to_bool(string) ⇒ Object



55
56
57
58
59
# File 'lib/generators/invoke_generators.rb', line 55

def to_bool(string)
  return unless string.is_a? String

  string.downcase == 'true'
end