Sha256: b1554bcc7667c1768f96474edfd9364a092d5d8c85702d08f4c6988b5157cdbd

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module AIRefactor
  module Refactors
    class Custom < BaseRefactor
      def run
        logger.verbose "Custom refactor to #{input_file}... (using user supplied prompt #{prompt_file_path || "from options"})"
        logger.verbose "Write output to #{output_file_path}..." if output_file_path

        begin
          output_content = process!(strip_ticks: false)
        rescue => e
          logger.error "Failed to process #{input_file}: #{e.message}"
          return false
        end

        return false unless output_content

        output_file_path ? true : output_content
      end

      def self.description
        "Generic refactor using user supplied prompt"
      end

      private

      def prompt_file_path
        return if options[:prompt]&.length&.positive?
        specified_prompt_path = options[:prompt_file_path]
        if specified_prompt_path&.length&.positive?
          if File.exist?(specified_prompt_path)
            return specified_prompt_path
          else
            logger.error "No prompt file '#{specified_prompt_path}' found"
          end
        else
          logger.error "No prompt file was specified!"
        end
        exit 1
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ai_refactor-0.6.0 lib/ai_refactor/refactors/custom.rb
ai_refactor-0.5.4 lib/ai_refactor/refactors/custom.rb
ai_refactor-0.5.3 lib/ai_refactor/refactors/custom.rb