Module: OllamaChat::Utils::FileArgument
- Defined in:
- lib/ollama_chat/utils/file_argument.rb
Overview
A module that provides functionality for handling file arguments and content retrieval.
The FileArgument module offers methods to process either file paths or direct string content, determining whether the input represents a file that should be read or if it’s already a string of content to be used directly. It also includes logic to handle default values when no valid input is provided.
Class Method Summary collapse
-
.get_file_argument(path_or_content, default: nil) ⇒ String
Returns the contents of a file or string, or a default value if neither is provided.
Class Method Details
.get_file_argument(path_or_content, default: nil) ⇒ String
Returns the contents of a file or string, or a default value if neither is provided.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ollama_chat/utils/file_argument.rb', line 41 def get_file_argument(path_or_content, default: nil) if path_or_content.present? && path_or_content.size < 2 ** 15 && File.basename(path_or_content).size < 2 ** 8 && File.exist?(path_or_content) then File.read(path_or_content) elsif path_or_content.present? path_or_content else default end end |