Class: Lemon::CLI::Generate

Inherits:
Base
  • Object
show all
Defined in:
lib/lemon/cli/generate.rb

Overview

Generate Command

Direct Known Subclasses

Scaffold

Instance Method Summary collapse

Methods inherited from Base

#initialize, #option_coverage, #option_dryrun, #option_format, #option_loadpath, #option_namespaces, #option_output, #option_parser, #option_private, #option_requires, #option_verbose, #option_zealous, #options, run, #run

Constructor Details

This class inherits a constructor from Lemon::CLI::Base

Instance Method Details

#command_parse(argv) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/lemon/cli/generate.rb', line 47

def command_parse(argv)
  option_parser.banner = "Usage: lemons generate [options] [files ...]"

  setup_options

  option_parser.parse!(argv)
end

#command_run(files) ⇒ Object

Generate test templates.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lemon/cli/generate.rb', line 12

def command_run(files)
  if i = files.index('-')
    options[:files] = files[0...i]
    options[:tests] = files[i+1..-1]
  else
    options[:files] = files
    options[:tests] = []
  end

  require 'lemon/coverage/generator'

  loadpath = options[:loadpath] || []
  requires = options[:requires] || []

  loadpath.each{ |path| $LOAD_PATH.unshift(path) }
  requires.each{ |path| require(path) }

  generator = Lemon::Generator.new(options)

  render_map = generator.generate

  generate_output(render_map)
end

#generate_output(render_map) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/lemon/cli/generate.rb', line 37

def generate_output(render_map)
  render_map.each do |group, test|
    puts "# --- #{group} ---"
    puts
    puts test
    puts
  end
end

#option_capsObject

-C –caps



76
77
78
79
80
# File 'lib/lemon/cli/generate.rb', line 76

def option_caps
  option_parser.on('-C', '--caps', 'use capitalized test terms') do
    options[:caps] = true
  end
end

#option_groupObject

-f –file



66
67
68
69
70
71
72
73
# File 'lib/lemon/cli/generate.rb', line 66

def option_group
  option_parser.on('-f', '--file', 'group tests by file') do
    options[:group] = :file
  end
  #option_parser.on('-c', '--case', 'group tests by case') do
  #  options[:group] = :case
  #end
end

#setup_optionsObject



56
57
58
59
60
61
62
63
# File 'lib/lemon/cli/generate.rb', line 56

def setup_options
  option_group
  option_namespaces
  option_private
  option_caps
  option_loadpath
  option_requires
end