Module: Susanoo::CLI::Commands::Generate

Extended by:
ActiveSupport::Concern
Included in:
ProjectInterface
Defined in:
lib/susanoo/cli/project_interface/generate.rb

Overview

Provide the generate & destroy commands for project wide usage.

Instance Method Summary collapse

Instance Method Details

#get_the_generator_class(generator_name) ⇒ Object (private)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/susanoo/cli/project_interface/generate.rb', line 49

def get_the_generator_class(generator_name)
  # Print the generators list and exit
  if generator_name.nil?
    print_generator_list
    return
  end

  # Try to load and get the generator Class
  begin
    klass = generator_name.downcase.camelize
    generator = Susanoo::Generators.const_get(klass)

  rescue NameError
    say_status 'Error', "Generator `#{generator_name}` not found.",
               :red
    exit 1
  end
  generator
end


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/susanoo/cli/project_interface/generate.rb', line 33

def print_generator_list
  say 'Available generators:'
  say '---------------------------------------------------'
  Susanoo::Generators.constants.each do |g|
    generator = Susanoo::Generators.const_get(g)

    if generator.respond_to?(:global_generator?) && \
      !generator.global_generator?
      generator_name = generator.to_s.split('::').last.underscore
      say "#{generator_name}\t\t #{generator.desc}\n"
    end

  end

end