Class: Vercon::Commands::Generate
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- Vercon::Commands::Generate
- Defined in:
- lib/vercon/commands/generate.rb
Constant Summary collapse
- AUTOFIXERS =
{ standard: "bundle exec standardrb --fix %{file} > /dev/null 2>&1", rubocop: "bundle exec rubocop -a %{file} > /dev/null 2>&1" }
Instance Method Summary collapse
- #call(path: nil, **opts) ⇒ Object
-
#initialize ⇒ Generate
constructor
A new instance of Generate.
Constructor Details
Instance Method Details
#call(path: nil, **opts) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vercon/commands/generate.rb', line 40 def call(path: nil, **opts) return unless can_generate?(path, opts) output_path = opts[:output_path] || generate_test_file_path(path, opts) return if output_path.nil? current_test = files.exist?(output_path) ? files.read(output_path) : nil result = generate_test_file(path, opts, current_test) return if result.nil? result = run_autofixes(result) if opts[:stdout] formatter = Rouge::Formatters::Terminal256.new(Rouge::Themes::Base16::Monokai.new) lexer = Rouge::Lexers::Ruby.new stdout.puts(formatter.format(lexer.lex(result))) return end if !opts[:force] && files.exist?(output_path) && stdout.no?("File already exists at \"#{output_path}\". Overwrite?") return end files.write(output_path, result) stdout.ok("Test file saved at \"#{output_path}\" 🥳") if opts[:open] == true || (opts[:open].nil? && config.open_by_default?) TTY::Editor.new(raise_on_failure: true).open(output_path) end end |