ollama_chat 0.0.25 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/spec_helper.rb CHANGED
@@ -12,44 +12,138 @@ require 'ollama_chat'
12
12
 
13
13
  ComplexConfig::Provider.deep_freeze = false
14
14
 
15
- def asset(name)
16
- File.join(__dir__, 'assets', name)
17
- end
15
+ # A module that provides helper methods for asset management within the
16
+ # application.
17
+ #
18
+ # The AssetHelpers module encapsulates functionality related to handling and
19
+ # processing application assets, such as CSS, JavaScript, and image files. It
20
+ # offers utilities for managing asset paths, generating URLs, and performing
21
+ # operations on assets during the application's runtime.
22
+ module AssetHelpers
23
+ # The asset method constructs and returns the full path to an asset file.
24
+ #
25
+ # This method takes a filename argument and combines it with the assets directory
26
+ # located within the same directory as the calling file, returning the
27
+ # complete path to that asset.
28
+ #
29
+ # @param name [String] the name of the asset file
30
+ #
31
+ # @return [String] the full path to the asset file
32
+ def asset(name)
33
+ File.join(__dir__, 'assets', name)
34
+ end
18
35
 
19
- def asset_content(name)
20
- File.read(File.join(__dir__, 'assets', name))
21
- end
36
+ # Reads and returns the content of an asset file from the assets directory.
37
+ #
38
+ # @param name [String] the name of the asset file to read
39
+ #
40
+ # @return [String] the content of the asset file as a string
41
+ def asset_content(name)
42
+ File.read(File.join(__dir__, 'assets', name))
43
+ end
22
44
 
23
- def asset_io(name, &block)
24
- io = File.new(File.join(__dir__, 'assets', name))
25
- if block
26
- begin
27
- block.call(io)
28
- ensure
29
- io.close
45
+ # The asset_io method retrieves an IO object for a specified asset file.
46
+ #
47
+ # This method constructs the path to an asset file within the assets directory
48
+ # and returns an IO object representing that file. If a block is provided, it
49
+ # yields the IO object to the block and ensures the file is properly closed
50
+ # after the block executes.
51
+ #
52
+ # @param name [ String ] the name of the asset file to retrieve
53
+ #
54
+ # @yield [ io ] yields the IO object for the asset file to the provided block
55
+ #
56
+ # @return [ File, nil ] returns the IO object for the asset file, or nil if a
57
+ # block is provided and the block does not return a value
58
+ def asset_io(name, &block)
59
+ io = File.new(File.join(__dir__, 'assets', name))
60
+ if block
61
+ begin
62
+ block.call(io)
63
+ ensure
64
+ io.close
65
+ end
66
+ else
67
+ io
30
68
  end
31
- else
32
- io
69
+ end
70
+
71
+ # The asset_json method reads and parses a JSON asset file.
72
+ #
73
+ # This method retrieves an asset by name, reads its contents from the
74
+ # filesystem, and then parses the resulting string as JSON, returning the
75
+ # parsed data structure.
76
+ #
77
+ # @param name [String] the name of the asset to retrieve and parse
78
+ #
79
+ # @return [Object] the parsed JSON data structure, typically a Hash or Array
80
+ def asset_json(name)
81
+ JSON(JSON(File.read(asset(name))))
33
82
  end
34
83
  end
35
84
 
36
- def asset_json(name)
37
- JSON(JSON(File.read(asset(name))))
85
+ # A module that provides functionality for stubbing Ollama server responses.
86
+ #
87
+ # The StubOllamaServer module enables developers to simulate Ollama API
88
+ # interactions in test environments by intercepting requests and returning
89
+ # predefined responses. This allows for faster, more reliable testing without
90
+ # requiring external service calls.
91
+ module StubOllamaServer
92
+ # The connect_to_ollama_server method establishes a connection to an Ollama
93
+ # server.
94
+ #
95
+ # This method sets up stubbed HTTP requests to simulate responses from an
96
+ # Ollama server, including API tags, show, and version endpoints. It can
97
+ # optionally instantiate a chat session after setting up the stubs.
98
+ #
99
+ # @param instantiate [Boolean] whether to instantiate a chat session after setting up stubs
100
+ def connect_to_ollama_server(instantiate: true)
101
+ before do
102
+ stub_request(:get, %r(/api/tags\z)).
103
+ to_return(status: 200, body: asset_json('api_tags.json'))
104
+ stub_request(:post, %r(/api/show\z)).
105
+ to_return(status: 200, body: asset_json('api_show.json'))
106
+ stub_request(:get, %r(/api/version\z)).
107
+ to_return(status: 200, body: asset_json('api_version.json'))
108
+ instantiate and chat
109
+ end
110
+ end
38
111
  end
39
112
 
40
- def connect_to_ollama_server(instantiate: true)
41
- before do
42
- stub_request(:get, %r(/api/tags\z)).
43
- to_return(status: 200, body: asset_json('api_tags.json'))
44
- stub_request(:post, %r(/api/show\z)).
45
- to_return(status: 200, body: asset_json('api_show.json'))
46
- stub_request(:get, %r(/api/version\z)).
47
- to_return(status: 200, body: asset_json('api_version.json'))
48
- instantiate and chat
113
+ # A module that provides functionality for protecting environment variables during tests.
114
+ #
115
+ # This module ensures that environment variable changes made during test execution
116
+ # are automatically restored to their original values after the test completes.
117
+ # It is designed to prevent side effects between tests that modify environment
118
+ # variables, maintaining a clean testing environment.
119
+ module ProtectEnvVars
120
+ # The apply method creates a lambda that protects environment variables
121
+ # during test execution.
122
+ #
123
+ # @return [Proc] a lambda that wraps test execution with environment variable
124
+ # preservation
125
+ def self.apply
126
+ -> example do
127
+ if example.metadata[:protect_env]
128
+ begin
129
+ stored_env = ENV.to_h
130
+ example.run
131
+ ensure
132
+ ENV.replace(stored_env)
133
+ end
134
+ else
135
+ example.run
136
+ end
137
+ end
49
138
  end
50
139
  end
51
140
 
52
141
  RSpec.configure do |config|
142
+ config.include AssetHelpers
143
+ config.extend StubOllamaServer
144
+
145
+ config.around(&ProtectEnvVars.apply)
146
+
53
147
  config.before(:suite) do
54
148
  infobar.show = nil
55
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.0'
18
+ version: '2.1'
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '2.0'
25
+ version: '2.1'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: all_images
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -414,9 +414,11 @@ extra_rdoc_files:
414
414
  - lib/ollama_chat/web_searching.rb
415
415
  files:
416
416
  - ".all_images.yml"
417
+ - ".contexts/code_comment.rb"
417
418
  - ".contexts/full.rb"
418
419
  - ".contexts/info.rb"
419
420
  - ".contexts/lib.rb"
421
+ - ".contexts/yard.md"
420
422
  - ".envrc"
421
423
  - ".gitignore"
422
424
  - CHANGES.md