foobara-local-files-crud-driver 0.0.7 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bde293f681140c57ca101373a28a20987460cc1923a4e84568d7cca322797c4
4
- data.tar.gz: 0fa8d9bdba2788c651e318ab0527f33811fffd8499da9c5f16cafe74956715ea
3
+ metadata.gz: ccd447447e2efe06faae51c0854796cd84087bd1c57e3e911c99bf02c3cc6f11
4
+ data.tar.gz: 8b1df78e975cbfca0f4bb5e863321e80dc2d0f28436e4ccf21cadf7ed54af769
5
5
  SHA512:
6
- metadata.gz: 4ce0c4090053c01aa1b9b26285268d34924d4a0f7b05c7b0df840b9ba4587d3564ab9bc344dee9dd91d6bee4fefc7fa1be71b4b2ad0e84098c58fb2b886b52e4
7
- data.tar.gz: f1d22a4b49d7d18aec84b117c5dbf4b043f44f2d176a4de213aaafc01babea800640ea9c778394984dacca3b77e8e5ec78be63a3030a81fd325b7d0e26cd0229
6
+ metadata.gz: 69cc3b74e0d6b8f4e0a846953785882034e87ba689ca4ada6c1801ee6cdf7318a3326006d3a7ca42f1bbb74b96e5434288e4192f5b4a19910307aef10d0e5404
7
+ data.tar.gz: f27c45f31e7994ee436edd6692b0ce299144f9c1bb0bd2d9b4db605061be16c03ba04c2a1be31f491c66c699eb7364959c435b30f3c529b1a44ae3d25673a4eb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.0.9] - 2025-04-15
2
+
3
+ - Remove unused #fsync
4
+ - Make sure we flush files to disk
5
+
6
+ ## [0.0.8] - 2025-03-29
7
+
8
+ - Fix bug where writing out one table erases another
9
+
1
10
  ## [0.0.7] - 2025-03-15
2
11
 
3
12
  - Make sure instances of Time and Date are written out in YAML-loadable ways
@@ -4,12 +4,11 @@ require "yaml"
4
4
  module Foobara
5
5
  # TODO: lots of duplication in this file. Need to DRY this up a bit.
6
6
  class LocalFilesCrudDriver < Persistence::EntityAttributesCrudDriver
7
- attr_accessor :data_path, :format, :fsync, :multi_process
7
+ attr_accessor :data_path, :format, :multi_process, :raw_data
8
8
 
9
- def initialize(data_path: "#{Dir.pwd}/local_data/records.yml", format: :yaml, fsync: false, multi_process: false)
9
+ def initialize(data_path: "#{Dir.pwd}/local_data/records.yml", format: :yaml, multi_process: false)
10
10
  self.data_path = data_path
11
11
  self.format = format
12
- self.fsync = fsync
13
12
  self.multi_process = multi_process
14
13
 
15
14
  unless format == :yaml
@@ -138,6 +137,10 @@ module Foobara
138
137
 
139
138
  private
140
139
 
140
+ def raw_data
141
+ crud_driver.raw_data
142
+ end
143
+
141
144
  def prepare_attributes_for_write(value)
142
145
  case value
143
146
  when ::Time
@@ -147,8 +150,8 @@ module Foobara
147
150
  when ::Array
148
151
  value.map { |element| prepare_attributes_for_write(element) }
149
152
  when ::Hash
150
- value.to_h do |key, value|
151
- [prepare_attributes_for_write(key), prepare_attributes_for_write(value)]
153
+ value.to_h do |key, inner_value|
154
+ [prepare_attributes_for_write(key), prepare_attributes_for_write(inner_value)]
152
155
  end
153
156
  else
154
157
  value
@@ -177,11 +180,11 @@ module Foobara
177
180
  f.flock(lock)
178
181
  yaml = f.read
179
182
  raw_data = yaml.empty? ? {} : YAML.load(yaml)
180
- @raw_data = raw_data unless multi_process
183
+ crud_driver.raw_data = raw_data unless multi_process
181
184
  yield raw_data, f
182
185
  end
183
- elsif defined?(@raw_data)
184
- yield @raw_data
186
+ elsif self.raw_data
187
+ yield self.raw_data
185
188
  else
186
189
  with_readable_raw_data(load: true, lock:, mode:, &)
187
190
  end
@@ -197,22 +200,24 @@ module Foobara
197
200
  f.truncate(0)
198
201
  f.rewind
199
202
  f.write(file_contents)
203
+ f.flush
200
204
  else
201
205
  FileUtils.mkdir_p File.dirname(data_path)
202
206
 
203
- File.open(data_path, "a+") do |f|
204
- f.flock(File::LOCK_EX)
205
- f.rewind
206
- retval = yield raw_data, f
207
+ File.open(data_path, "a+") do |file|
208
+ file.flock(File::LOCK_EX)
209
+ file.rewind
210
+ retval = yield raw_data, file
207
211
  file_contents = YAML.dump(raw_data)
208
- f.truncate(0)
209
- f.rewind
210
- f.write(file_contents)
212
+ file.truncate(0)
213
+ file.rewind
214
+ file.write(file_contents)
215
+ file.flush
211
216
  end
212
217
  end
213
218
 
214
219
  unless multi_process
215
- @raw_data = raw_data
220
+ crud_driver.raw_data = raw_data
216
221
  end
217
222
  end
218
223
 
metadata CHANGED
@@ -1,28 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-local-files-crud-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0'
18
+ version: 0.0.102
19
19
  type: :runtime
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: '0'
25
+ version: 0.0.102
26
26
  email:
27
27
  - azimux@gmail.com
28
28
  executables: []
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
- rubygems_version: 3.6.6
60
+ rubygems_version: 3.6.7
61
61
  specification_version: 4
62
62
  summary: Stores all record data in a yaml file in a local directory
63
63
  test_files: []