class Lemon::CLI::Scaffold
Scaffold
Command
Public Instance Methods
append_test(file, test)
click to toggle source
Append tests to file.
# File lib/lemon/cli/scaffold.rb, line 100 def append_test(file, test) return if test.strip.empty? if dryrun? puts "[DRYRUN] append #{file}" else dir = File.dirname(file) FileUtils.mkdir_p(dir) unless File.directory?(dir) File.open(file, 'a'){ |f| f << "\n" + test.to_s } puts "append #{file}" end end
command_parse(argv)
click to toggle source
# File lib/lemon/cli/scaffold.rb, line 33 def command_parse(argv) option_parser.banner = "Usage: lemons scaffold [options] [files ...]" setup_options option_parser.parse!(argv) end
dryrun?()
click to toggle source
# File lib/lemon/cli/scaffold.rb, line 58 def dryrun? options[:dryrun] end
generate_output(render_map)
click to toggle source
output()
click to toggle source
Output directory, default is `test`.
# File lib/lemon/cli/scaffold.rb, line 51 def output options[:output] || 'test' end
setup_options()
click to toggle source
Calls superclass method
Lemon::CLI::Generate#setup_options
# File lib/lemon/cli/scaffold.rb, line 42 def setup_options option_output option_dryrun super end
test_file(group)
click to toggle source
Given the group name, convert it to a suitable test file name.
# File lib/lemon/cli/scaffold.rb, line 65 def test_file(group) if options[:group] == :file file = group else file = group.gsub('::', '/').downcase end dirname, basename = File.split(file) if i = dirname.index('/') dirname = dirname[i+1..-1] file = File.join(dirname, output, "case_#{basename}") else file = File.join(output, "case_#{basename}") end end
write_test(file, test)
click to toggle source
Write test file.
# File lib/lemon/cli/scaffold.rb, line 85 def write_test(file, test) return if test.strip.empty? if dryrun? puts "[DRYRUN] write #{file}" else dir = File.dirname(file) FileUtils.mkdir_p(dir) unless File.directory?(dir) File.open(file, 'w'){ |f| f << test.to_s } puts "write #{file}" end end