foobara-local-files-crud-driver 0.0.6 → 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 +4 -4
- data/CHANGELOG.md +8 -0
- data/src/foobara/local_files_crud_driver.rb +37 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac3f878951193768f4270053f52ef083fdded58e48365dfe02884495a365c9e2
|
4
|
+
data.tar.gz: a0bcaa7c8d7565842d64c5d0efa2e7cea005c168b6e2d71bd192a5b09dc67b00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f69ebb37262f861fa0f8881dedc0f8d663ab2c8c74ba51ae3afe37c0e53fe684dfd44a74c0c7c49431ff5b0b44c244d304c91d5bf0da00828fcb9dd47eeaab9
|
7
|
+
data.tar.gz: 06da6c67ba0d4891841757ea60b8326fa344749a5a12b3a62250e28554f39a40b333cb9bb202bf70176df273b2aac8421e63d43634ec262055c44a11c25508cc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.0.8] - 2025-03-29
|
2
|
+
|
3
|
+
- Fix bug where writing out one table erases another
|
4
|
+
|
5
|
+
## [0.0.7] - 2025-03-15
|
6
|
+
|
7
|
+
- Make sure instances of Time and Date are written out in YAML-loadable ways
|
8
|
+
|
1
9
|
## [0.0.6] - 2025-03-15
|
2
10
|
|
3
11
|
- Safety improvement: do not truncate file if we fail to generate record yaml
|
@@ -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
|
@@ -64,7 +64,8 @@ module Foobara
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def insert(attributes)
|
67
|
-
attributes =
|
67
|
+
attributes = prepare_attributes_for_write(attributes)
|
68
|
+
|
68
69
|
record_id = record_id_for(attributes)
|
69
70
|
|
70
71
|
unless record_id
|
@@ -91,6 +92,8 @@ module Foobara
|
|
91
92
|
end
|
92
93
|
|
93
94
|
def update(attributes)
|
95
|
+
attributes = prepare_attributes_for_write(attributes)
|
96
|
+
|
94
97
|
with_writeable_raw_data do |raw_data|
|
95
98
|
attributes = Util.deep_dup(attributes)
|
96
99
|
|
@@ -135,6 +138,27 @@ module Foobara
|
|
135
138
|
|
136
139
|
private
|
137
140
|
|
141
|
+
def raw_data
|
142
|
+
crud_driver.raw_data
|
143
|
+
end
|
144
|
+
|
145
|
+
def prepare_attributes_for_write(value)
|
146
|
+
case value
|
147
|
+
when ::Time
|
148
|
+
value.to_f
|
149
|
+
when ::Date
|
150
|
+
value.to_s
|
151
|
+
when ::Array
|
152
|
+
value.map { |element| prepare_attributes_for_write(element) }
|
153
|
+
when ::Hash
|
154
|
+
value.to_h do |key, inner_value|
|
155
|
+
[prepare_attributes_for_write(key), prepare_attributes_for_write(inner_value)]
|
156
|
+
end
|
157
|
+
else
|
158
|
+
value
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
138
162
|
def data_path
|
139
163
|
crud_driver.data_path
|
140
164
|
end
|
@@ -157,11 +181,11 @@ module Foobara
|
|
157
181
|
f.flock(lock)
|
158
182
|
yaml = f.read
|
159
183
|
raw_data = yaml.empty? ? {} : YAML.load(yaml)
|
160
|
-
|
184
|
+
crud_driver.raw_data = raw_data unless multi_process
|
161
185
|
yield raw_data, f
|
162
186
|
end
|
163
|
-
elsif
|
164
|
-
yield
|
187
|
+
elsif self.raw_data
|
188
|
+
yield self.raw_data
|
165
189
|
else
|
166
190
|
with_readable_raw_data(load: true, lock:, mode:, &)
|
167
191
|
end
|
@@ -180,19 +204,19 @@ module Foobara
|
|
180
204
|
else
|
181
205
|
FileUtils.mkdir_p File.dirname(data_path)
|
182
206
|
|
183
|
-
File.open(data_path, "a+") do |
|
184
|
-
|
185
|
-
|
186
|
-
retval = yield raw_data,
|
207
|
+
File.open(data_path, "a+") do |file|
|
208
|
+
file.flock(File::LOCK_EX)
|
209
|
+
file.rewind
|
210
|
+
retval = yield raw_data, file
|
187
211
|
file_contents = YAML.dump(raw_data)
|
188
|
-
|
189
|
-
|
190
|
-
|
212
|
+
file.truncate(0)
|
213
|
+
file.rewind
|
214
|
+
file.write(file_contents)
|
191
215
|
end
|
192
216
|
end
|
193
217
|
|
194
218
|
unless multi_process
|
195
|
-
|
219
|
+
crud_driver.raw_data = raw_data
|
196
220
|
end
|
197
221
|
end
|
198
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.
|
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-
|
10
|
+
date: 2025-03-29 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: foobara
|
@@ -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.
|
60
|
+
rubygems_version: 3.6.6
|
61
61
|
specification_version: 4
|
62
62
|
summary: Stores all record data in a yaml file in a local directory
|
63
63
|
test_files: []
|