foobara-local-files-crud-driver 0.1.0 → 0.2.0

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: 609ee6a6e67f8a1eef738ae19ab81431b09fd00c93c3464a0ee7b2349d01a9b9
4
- data.tar.gz: c5d8a6c059af7083c223566d35719c52de538adda4fe41515893e6ac22c0c789
3
+ metadata.gz: 3d04168a39dfacd34feb65dbd92f779f4d75c723037202db838f6b3554c1ace6
4
+ data.tar.gz: 61abb7b920fd5a99f6e07db794d1e3b7bd07786ec7045368c587407a5555f307
5
5
  SHA512:
6
- metadata.gz: 9656aef4e5eaa89e134a582c11ecbcd4669cac3ab251de4a687ddc85a2243fef72212dea0f6c6ea653fd3df0f7dea54299002841214fe5ed00ca47892d17f1c6
7
- data.tar.gz: 32be85a9a1820ff8fb138abdf61a798d342d6b239e007d152ceb347de51028cad5c444f47ab34e765e611d5f5a029d98b10e489fe200d11f1f9d7b8d8b4a776a
6
+ metadata.gz: 8b52e04c115e67d6989f7ccae5299d68985fea4ff480716d794a792746ba2beb41d1a45a836232ffa0a3ddce3f43e6053469c73d588873fb5cda0bfd2f864a4f
7
+ data.tar.gz: 9f9926681ff740ff1f7789ae1276bf16bfe6579128e141b2da8a0096268729d0ee5431fc7eb6001cf0bea90e62c007c35298a79578e4fc0b54dba8f209f36ec3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.2.0] - 2025-10-21
2
+
3
+ !!!WARNING! This will no-longer be able to access old records in recrods.yml!
4
+ If this impacts you let me know and I can help you migrate!!! Or pin to < 0.2.0 but still inform me please!
5
+
6
+ - Write data to one-file-per-entity-class instead of one big file
7
+ - Fix bug that passes invalid options to EntityAttributesCrudDriver#initialize
8
+
1
9
  ## [0.0.10] - 2025-06-16
2
10
 
3
11
  - Move crud-driver-specific specs to foobara-crud-driver-spec-helpers gem
@@ -4,9 +4,9 @@ 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, :multi_process, :raw_data
7
+ attr_accessor :data_path, :format, :multi_process
8
8
 
9
- def initialize(data_path: "#{Dir.pwd}/local_data/records.yml", format: :yaml, multi_process: false)
9
+ def initialize(data_path: "#{Dir.pwd}/local_data/", format: :yaml, multi_process: false, **)
10
10
  self.data_path = data_path
11
11
  self.format = format
12
12
  self.multi_process = multi_process
@@ -17,13 +17,15 @@ module Foobara
17
17
  # :nocov:
18
18
  end
19
19
 
20
- super
20
+ super(**)
21
21
  end
22
22
 
23
23
  class Table < Persistence::EntityAttributesCrudDriver::Table
24
+ attr_accessor :raw_data
25
+
24
26
  def get_id
25
27
  with_writeable_raw_data do |raw_data|
26
- table_data = raw_data[table_name] ||= {}
28
+ table_data = raw_data || {}
27
29
  sequence_value = table_data["sequence"] || 1
28
30
  table_data["sequence"] = sequence_value + 1
29
31
 
@@ -33,19 +35,19 @@ module Foobara
33
35
 
34
36
  def all(page_size: nil)
35
37
  with_readable_raw_data do |raw_data|
36
- raw_data[table_name]&.[]("records")&.values || []
38
+ raw_data&.[]("records")&.values || []
37
39
  end
38
40
  end
39
41
 
40
42
  def count
41
43
  with_readable_raw_data do |raw_data|
42
- raw_data[table_name]&.[]("records")&.size || 0
44
+ raw_data&.[]("records")&.size || 0
43
45
  end
44
46
  end
45
47
 
46
48
  def find(record_id)
47
49
  with_readable_raw_data do |raw_data|
48
- raw_data[table_name]&.[]("records")&.[](record_id)
50
+ raw_data&.[]("records")&.[](record_id)
49
51
  end
50
52
  end
51
53
 
@@ -73,7 +75,7 @@ module Foobara
73
75
  end
74
76
 
75
77
  with_writeable_raw_data do |raw_data|
76
- table_data = raw_data[table_name] ||= {}
78
+ table_data = raw_data || {}
77
79
  records = table_data["records"] ||= {}
78
80
 
79
81
  if record_id
@@ -98,7 +100,7 @@ module Foobara
98
100
 
99
101
  record_id = record_id_for(attributes)
100
102
 
101
- table_data = raw_data[table_name] ||= {}
103
+ table_data = raw_data || {}
102
104
  records = table_data["records"] ||= {}
103
105
 
104
106
  unless records.key?(record_id)
@@ -115,7 +117,7 @@ module Foobara
115
117
 
116
118
  def hard_delete(record_id)
117
119
  with_writeable_raw_data do |raw_data|
118
- table_data = raw_data[table_name] ||= {}
120
+ table_data = raw_data || {}
119
121
  records = table_data["records"] ||= {}
120
122
 
121
123
  unless records.key?(record_id)
@@ -130,17 +132,13 @@ module Foobara
130
132
 
131
133
  def hard_delete_all
132
134
  with_writeable_raw_data do |raw_data|
133
- table_data = raw_data[table_name] ||= {}
135
+ table_data = raw_data || {}
134
136
  table_data["records"] = {}
135
137
  end
136
138
  end
137
139
 
138
140
  private
139
141
 
140
- def raw_data
141
- crud_driver.raw_data
142
- end
143
-
144
142
  def prepare_attributes_for_write(value)
145
143
  case value
146
144
  when ::Time
@@ -159,7 +157,7 @@ module Foobara
159
157
  end
160
158
 
161
159
  def data_path
162
- crud_driver.data_path
160
+ "#{crud_driver.data_path}/#{table_name}.yml"
163
161
  end
164
162
 
165
163
  def multi_process
@@ -180,7 +178,7 @@ module Foobara
180
178
  f.flock(lock)
181
179
  yaml = f.read
182
180
  raw_data = yaml.empty? ? {} : YAML.load(yaml)
183
- crud_driver.raw_data = raw_data unless multi_process
181
+ self.raw_data = raw_data unless multi_process
184
182
  yield raw_data, f
185
183
  end
186
184
  elsif self.raw_data
@@ -217,7 +215,7 @@ module Foobara
217
215
  end
218
216
 
219
217
  unless multi_process
220
- crud_driver.raw_data = raw_data
218
+ self.raw_data = raw_data
221
219
  end
222
220
  end
223
221
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-local-files-crud-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -15,7 +15,7 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.1.1
18
+ version: 0.2.0
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.0.0
@@ -25,7 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 0.1.1
28
+ version: 0.2.0
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: 2.0.0