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

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: ac3f878951193768f4270053f52ef083fdded58e48365dfe02884495a365c9e2
4
+ data.tar.gz: a0bcaa7c8d7565842d64c5d0efa2e7cea005c168b6e2d71bd192a5b09dc67b00
5
5
  SHA512:
6
- metadata.gz: 4ce0c4090053c01aa1b9b26285268d34924d4a0f7b05c7b0df840b9ba4587d3564ab9bc344dee9dd91d6bee4fefc7fa1be71b4b2ad0e84098c58fb2b886b52e4
7
- data.tar.gz: f1d22a4b49d7d18aec84b117c5dbf4b043f44f2d176a4de213aaafc01babea800640ea9c778394984dacca3b77e8e5ec78be63a3030a81fd325b7d0e26cd0229
6
+ metadata.gz: 1f69ebb37262f861fa0f8881dedc0f8d663ab2c8c74ba51ae3afe37c0e53fe684dfd44a74c0c7c49431ff5b0b44c244d304c91d5bf0da00828fcb9dd47eeaab9
7
+ data.tar.gz: 06da6c67ba0d4891841757ea60b8326fa344749a5a12b3a62250e28554f39a40b333cb9bb202bf70176df273b2aac8421e63d43634ec262055c44a11c25508cc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.8] - 2025-03-29
2
+
3
+ - Fix bug where writing out one table erases another
4
+
1
5
  ## [0.0.7] - 2025-03-15
2
6
 
3
7
  - Make sure instances of Time and Date are written out in YAML-loadable ways
@@ -4,7 +4,7 @@ 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, :fsync, :multi_process, :raw_data
8
8
 
9
9
  def initialize(data_path: "#{Dir.pwd}/local_data/records.yml", format: :yaml, fsync: false, multi_process: false)
10
10
  self.data_path = data_path
@@ -138,6 +138,10 @@ module Foobara
138
138
 
139
139
  private
140
140
 
141
+ def raw_data
142
+ crud_driver.raw_data
143
+ end
144
+
141
145
  def prepare_attributes_for_write(value)
142
146
  case value
143
147
  when ::Time
@@ -147,8 +151,8 @@ module Foobara
147
151
  when ::Array
148
152
  value.map { |element| prepare_attributes_for_write(element) }
149
153
  when ::Hash
150
- value.to_h do |key, value|
151
- [prepare_attributes_for_write(key), prepare_attributes_for_write(value)]
154
+ value.to_h do |key, inner_value|
155
+ [prepare_attributes_for_write(key), prepare_attributes_for_write(inner_value)]
152
156
  end
153
157
  else
154
158
  value
@@ -177,11 +181,11 @@ module Foobara
177
181
  f.flock(lock)
178
182
  yaml = f.read
179
183
  raw_data = yaml.empty? ? {} : YAML.load(yaml)
180
- @raw_data = raw_data unless multi_process
184
+ crud_driver.raw_data = raw_data unless multi_process
181
185
  yield raw_data, f
182
186
  end
183
- elsif defined?(@raw_data)
184
- yield @raw_data
187
+ elsif self.raw_data
188
+ yield self.raw_data
185
189
  else
186
190
  with_readable_raw_data(load: true, lock:, mode:, &)
187
191
  end
@@ -200,19 +204,19 @@ module Foobara
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)
211
215
  end
212
216
  end
213
217
 
214
218
  unless multi_process
215
- @raw_data = raw_data
219
+ crud_driver.raw_data = raw_data
216
220
  end
217
221
  end
218
222
 
metadata CHANGED
@@ -1,13 +1,13 @@
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.8
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: 2025-03-29 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara