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



31
32
33
# File 'lib/generators/invoke_generators.rb', line 31

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

.collect_skip_flags(structure) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/invoke_generators.rb', line 48

def collect_skip_flags(structure)
  flags = []
  flags << 'skip_allure' if structure[:skip_allure]
  flags << 'skip_video' if structure[:skip_video]
  flags << 'axe_addon' if structure[:accessibility] && !mobile_automation?(structure[:automation])
  flags << 'visual_addon' if structure[:visual] && !mobile_automation?(structure[:automation])
  flags << 'lighthouse_addon' if structure[:performance] && !mobile_automation?(structure[:automation])
  flags << "ruby_version:#{structure[:ruby_version]}" if structure[:ruby_version]
  flags.concat(reporter_flags(structure[:reporter]))
  flags
end

.generate_framework(structure = {}) ⇒ Object



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

def generate_framework(structure = {})
  generators = %w[Automation Common Helpers]
  framework = structure[:framework]
  add_generator(generators, framework.capitalize)
  add_generator(generators, structure[:ci_platform].capitalize) if !structure[:skip_ci] && (structure[:ci_platform])
  extra_args = collect_skip_flags(structure)
  generators.each do |generator|
    invoke_generator({
                       automation: structure[:automation],
                       framework:,
                       generator:,
                       ci_platform: structure[:ci_platform],
                       name: structure[:name],
                       extra_args:
                     })
  end
end

.invoke_generator(structure = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/generators/invoke_generators.rb', line 38

def invoke_generator(structure = {})
  args = [structure[:automation], structure[:framework], structure[:name], structure[:ci_platform]]
  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)


72
73
74
# File 'lib/generators/invoke_generators.rb', line 72

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

.reporter_flags(reporter) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/invoke_generators.rb', line 60

def reporter_flags(reporter)
  case reporter
  when 'allure' then ['reporter_allure']
  when 'junit' then ['reporter_junit']
  when 'json' then ['reporter_json']
  when 'both' then %w[reporter_allure reporter_junit]
  when 'all' then %w[reporter_allure reporter_junit reporter_json]
  when 'none' then ['reporter_none']
  else []
  end
end

.to_bool(string) ⇒ Object



76
77
78
79
80
# File 'lib/generators/invoke_generators.rb', line 76

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

  string.downcase == 'true'
end