lib/ollama/utils/file_argument.rb in ollama-ruby-0.3.2 vs lib/ollama/utils/file_argument.rb in ollama-ruby-0.4.0
- old
+ new
@@ -1,7 +1,25 @@
module Ollama::Utils::FileArgument
module_function
+ # Returns the contents of a file or string, or a default value if neither is provided.
+ #
+ # @param [String] path_or_content The path to a file or a string containing
+ # the content.
+ #
+ # @param [String] default The default value to return if no valid input is
+ # given. Defaults to nil.
+ #
+ # @return [String] The contents of the file, the string, or the default value.
+ #
+ # @example Get the contents of a file
+ # get_file_argument('path/to/file')
+ #
+ # @example Use a string as content
+ # get_file_argument('string content')
+ #
+ # @example Return a default value if no valid input is given
+ # get_file_argument(nil, default: 'default content')
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