Module: OllamaChat::ConfigHandling

Extended by:
Tins::Concern
Included in:
Chat
Defined in:
lib/ollama_chat/config_handling.rb

Overview

Provides functionality for handling configuration files and settings for OllamaChat. It loads configuration from YAML files, supports environment variable overrides, and offers methods to read and write configuration data. The module also ensures default values are set and validates configuration structure.

Instance Method Summary collapse

Instance Method Details

#configComplexConfig::Settings

The config method returns the configuration object associated with the class.

Returns:

  • (ComplexConfig::Settings)

    the configuration instance



21
22
23
# File 'lib/ollama_chat/config_handling.rb', line 21

def config
  self.class.config
end

#run_syntax_check(checker, path) ⇒ Hash?

Runs the syntax checker on the given file and returns a result hash.

Parameters:

  • checker (ComplexConfig::Settings)

    the resolved checker config

  • path (String, Pathname)

    the file to check

Returns:

  • (Hash, nil)

    { status:, output: } or nil if binary is missing



45
46
47
48
49
50
51
52
53
# File 'lib/ollama_chat/config_handling.rb', line 45

def run_syntax_check(checker, path)
  _stdout, stderr, status = Open3.capture3(*checker.cmd, path.to_s)
  {
    status: status.success? ? 'pass' : 'fail',
    output: stderr.strip
  }
rescue Errno::ENOENT
  nil
end

#syntax_checker_for(path) ⇒ ComplexConfig::Settings?

Returns the first enabled syntax checker whose suffixes match the given file's extension, or nil if no match.

Parameters:

  • path (String, Pathname)

    the file path to check

Returns:

  • (ComplexConfig::Settings, nil)

    the matching checker config



30
31
32
33
34
35
36
37
38
# File 'lib/ollama_chat/config_handling.rb', line 30

def syntax_checker_for(path)
  path = Pathname.new(path)
  ext = path.extname.delete_prefix(?.).full? or return
  config.syntax_checkers.attribute_values.each do |checker|
    next unless checker.enabled
    return checker if checker.suffixes.include?(ext)
  end
  nil
end