Sha256: d138f436d6eab7e90b91e9dce56dbbacb9c6c2b6f8b1abc1dec67620c087c08d
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module AIRefactor class BaseRefactor attr_reader :input_file, :options, :logger attr_writer :failed_message def initialize(input_file, options, logger) @input_file = input_file @options = options @logger = logger end def run raise NotImplementedError end def failed_message @failed_message || "Reason not specified" end private def prompt_file_path self.class.prompt_file_path end def ai_client @ai_client ||= OpenAI::Client.new end class << self def command_line_options [] end def refactor_name name.split("::") .last .gsub(/::/, "/") .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .downcase end def prompt_file_path file = if options[:prompt_file_path]&.length&.positive? options[:prompt_file_path] else File.join(File.dirname(File.expand_path(__FILE__)), "prompts", "#{refactor_name}.md") end file.tap do |prompt| raise "No prompt file '#{prompt}' found for #{refactor_name}" unless File.exist?(prompt) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ai_refactor-0.2.0 | lib/ai_refactor/base_refactor.rb |