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 +4 -4
- data/CHANGELOG.md +4 -0
- data/src/foobara/local_files_crud_driver.rb +18 -14
- metadata +2 -2
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
@@ -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,
|
151
|
-
[prepare_attributes_for_write(key), prepare_attributes_for_write(
|
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
|
-
|
184
|
+
crud_driver.raw_data = raw_data unless multi_process
|
181
185
|
yield raw_data, f
|
182
186
|
end
|
183
|
-
elsif
|
184
|
-
yield
|
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 |
|
204
|
-
|
205
|
-
|
206
|
-
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
|
207
211
|
file_contents = YAML.dump(raw_data)
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
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.
|
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
|