Class: AIRefactor::FileProcessor
- Inherits:
-
Object
- Object
- AIRefactor::FileProcessor
- Defined in:
- lib/ai_refactor/file_processor.rb
Instance Attribute Summary collapse
-
#input_file_path ⇒ Object
readonly
Returns the value of attribute input_file_path.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
Instance Method Summary collapse
-
#initialize(prompt:, ai_client:, logger:, output_path: nil, options: {}) ⇒ FileProcessor
constructor
A new instance of FileProcessor.
- #output_exists? ⇒ Boolean
- #process! ⇒ Object
Constructor Details
#initialize(prompt:, ai_client:, logger:, output_path: nil, options: {}) ⇒ FileProcessor
Returns a new instance of FileProcessor.
11 12 13 14 15 16 17 |
# File 'lib/ai_refactor/file_processor.rb', line 11 def initialize(prompt:, ai_client:, logger:, output_path: nil, options: {}) @prompt = prompt @ai_client = ai_client @logger = logger @output_path = output_path @options = end |
Instance Attribute Details
#input_file_path ⇒ Object (readonly)
Returns the value of attribute input_file_path.
9 10 11 |
# File 'lib/ai_refactor/file_processor.rb', line 9 def input_file_path @input_file_path end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/ai_refactor/file_processor.rb', line 9 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/ai_refactor/file_processor.rb', line 9 def @options end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
9 10 11 |
# File 'lib/ai_refactor/file_processor.rb', line 9 def output_path @output_path end |
Instance Method Details
#output_exists? ⇒ Boolean
19 20 21 22 |
# File 'lib/ai_refactor/file_processor.rb', line 19 def output_exists? return false unless output_path File.exist?(output_path) end |
#process! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ai_refactor/file_processor.rb', line 24 def process! logger.debug("Processing #{@prompt.input_file_path} with prompt in #{.prompt_file_path}") logger.debug("Options: #{.inspect}") = @prompt. if [:review_prompt] logger.info "Review prompt:\n" .each do || logger.info "\n-- Start of prompt for Role #{[:role]} --\n" logger.info [:content] logger.info "\n-- End of prompt for Role #{[:role]} --\n" end return [nil, "Skipped as review prompt was requested", nil] end content, finished_reason, usage = (, , ai_max_attempts) content = if content && content.length > 0 processed = block_given? ? yield(content) : content if output_path write_output(output_path, processed) logger.verbose "Wrote output to #{output_path}..." end processed end [content, finished_reason, usage] end |