Module: Couch::Generators

Defined in:
lib/couch/generators.rb,
lib/couch/generators/base.rb,
lib/couch/generators/named_base.rb,
lib/couch/generators/list/list_generator.rb,
lib/couch/generators/show/show_generator.rb,
lib/couch/generators/view/view_generator.rb,
lib/couch/generators/scaffold/scaffold_generator.rb,
lib/couch/generators/validation/validation_generator.rb,
lib/couch/generators/application/application_generator.rb

Defined Under Namespace

Classes: ApplicationGenerator, Base, Error, ListGenerator, NamedBase, ScaffoldGenerator, ShowGenerator, ValidationGenerator, ViewGenerator

Class Method Summary collapse

Class Method Details

.help(command = 'generate') ⇒ Object

Show help message with available generators.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/couch/generators.rb', line 18

def self.help(command = 'generate')
  path = File.expand_path("../generators/*/*_generator.rb", __FILE__)
  generators = Dir.glob(path)
  generators.sort!
  generators.map! { |f| File.basename(f) }
  generators.map! { |n| n.sub!(/_generator\.rb$/, '')  }
  longest_name_size = generators.map { |g| g.size }.sort.last
  generators.map! { |g| "%s  # %s" % [g.ljust(longest_name_size), lookup(g).info] }

  puts "Usage: couch #{command} GENERATOR [args] [options]"
  puts
  puts "General options:"
  puts "  -h, [--help]     # Print generators options and usage"
  puts "  -p, [--pretend]  # Run but do not make any changes"
  puts "  -f, [--force]    # Overwrite files that already exist"
  puts "  -s, [--skip]     # Skip files that already exist"
  puts "  -q, [--quiet]    # Supress status output"
  puts
  puts "Please choose a generator below:"
  puts
  puts generators
end

.invoke(name, args = ARGV, config = {}) ⇒ Object

Receives a name, arguments and the behavior to invoke the generator. It’s used as the default entry point for generate and destroy commands.



8
9
10
11
12
13
14
15
# File 'lib/couch/generators.rb', line 8

def self.invoke(name, args = ARGV, config = {})
  if klass = lookup(name.to_s)
    args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
    klass.start(args, config)
  else
    puts "Could not find generator #{name}."
  end
end