Class: AIRefactor::Refactors::Ruby::WriteRbs
- Inherits:
-
BaseRefactor
- Object
- BaseRefactor
- AIRefactor::Refactors::Ruby::WriteRbs
- Defined in:
- lib/ai_refactor/refactors/ruby/write_rbs.rb
Instance Attribute Summary
Attributes inherited from BaseRefactor
#ai_client, #failed_message, #input_content, #input_file, #logger, #options
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from BaseRefactor
command_line_options, inherited, #initialize, refactor_name, takes_input_files?
Constructor Details
This class inherits a constructor from AIRefactor::Refactors::BaseRefactor
Class Method Details
.description ⇒ Object
40 41 42 |
# File 'lib/ai_refactor/refactors/ruby/write_rbs.rb', line 40 def self.description "User supplied prompt to write RBS for some Ruby" end |
Instance Method Details
#default_output_path ⇒ Object
44 45 46 |
# File 'lib/ai_refactor/refactors/ruby/write_rbs.rb', line 44 def default_output_path File.join("sig", input_file.gsub(/\.rb$/, ".rbs")) end |
#run ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ai_refactor/refactors/ruby/write_rbs.rb', line 7 def run logger.verbose "Write some RBS for #{input_file}..." logger.verbose "Write output to #{output_file_path}..." if output_file_path begin output_content = process!(strip_ticks: true) rescue => e logger.error "Failed to process #{input_file}: #{e.}" return false end return false unless output_content if output_file_path steep_runner = AIRefactor::TestRunners::SteepRunner.new(input_file, command_template: .minitest_run_command) logger.verbose "Run steep against generated RBS file #{output_file_path} (`#{steep_runner.command}`)..." test_run = steep_runner.run if test_run.failed? logger.warn "#{input_file} was translated to #{output_file_path} but the resulting RBS fails to pass a steep check..." logger.error "Failed to run test, exited with status #{test_run.exitstatus}. Stdout: #{test_run.stdout}\n\nStderr: #{test_run.stderr}\n\n" logger.error "New RBS failed!", bold: true self. = "Generated RBS file failed to pass checks" return false end logger.verbose "\nNew RBS file passed checks" end output_file_path ? true : output_content end |