lucarecord 0.2.15 → 0.2.16
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/lib/luca_record/io.rb +32 -2
- data/lib/luca_record/version.rb +1 -1
- data/lib/luca_support/code.rb +1 -1
- 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: 222229f2cc5299302f8ff1df81a92ce9a507101e6035765cdaa1408ad8e93365
|
4
|
+
data.tar.gz: 30102479db3e25fca972cf723d8f679891a179ed0b9ceb79cb03d2b22f25743b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be9918878c1d9204ccbaac61cfefac3872b028d192e8013d177fda369092dcd1ff2884e7e0e53a1384e3e9b21f57cbca903b6f448bddb39ec2199dd4aefdf46
|
7
|
+
data.tar.gz: b5730ce678fc0259a4550f14fddce5655509d07653c0fd8d405d9d1f0f3e48572cad1818790e29ead2d23144be95a3b9229aaf424bca4b71b61c12603b16c0fc
|
data/lib/luca_record/io.rb
CHANGED
@@ -29,7 +29,7 @@ module LucaRecord # :nodoc:
|
|
29
29
|
|
30
30
|
# find ID based record. Support uuid and encoded date.
|
31
31
|
def find(id, basedir = @dirname)
|
32
|
-
return enum_for(:find, id, basedir) unless block_given?
|
32
|
+
return enum_for(:find, id, basedir).first unless block_given?
|
33
33
|
|
34
34
|
if id.length >= 40
|
35
35
|
open_hashed(basedir, id) do |f|
|
@@ -91,6 +91,7 @@ module LucaRecord # :nodoc:
|
|
91
91
|
|
92
92
|
# create hash based record
|
93
93
|
def create(obj, basedir = @dirname)
|
94
|
+
validate_keys(obj)
|
94
95
|
id = LucaSupport::Code.issue_random_id
|
95
96
|
obj['id'] = id
|
96
97
|
open_hashed(basedir, id, 'w') do |f|
|
@@ -121,6 +122,25 @@ module LucaRecord # :nodoc:
|
|
121
122
|
File.write(path, YAML.dump(origin.sort.to_h))
|
122
123
|
end
|
123
124
|
|
125
|
+
# update file with obj['id']
|
126
|
+
def save(obj, basedir = @dirname)
|
127
|
+
if obj['id'].nil?
|
128
|
+
create(obj, basedir)
|
129
|
+
else
|
130
|
+
validate_keys(obj)
|
131
|
+
open_hashed(basedir, obj['id'], 'w') do |f|
|
132
|
+
f.write(YAML.dump(obj.sort.to_h))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
obj['id']
|
136
|
+
end
|
137
|
+
|
138
|
+
# delete file by id
|
139
|
+
def delete(id, basedir = @dirname)
|
140
|
+
FileUtils.rm(Pathname(abs_path(basedir)) / id2path(id))
|
141
|
+
id
|
142
|
+
end
|
143
|
+
|
124
144
|
# ----------------------------------------------------------------
|
125
145
|
# :section: Path Utilities
|
126
146
|
# ----------------------------------------------------------------
|
@@ -234,7 +254,17 @@ module LucaRecord # :nodoc:
|
|
234
254
|
when 'json'
|
235
255
|
# TODO: implement JSON parse
|
236
256
|
else
|
237
|
-
YAML.load(io.read)
|
257
|
+
YAML.load(io.read).tap { |obj| validate_keys(obj) }
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def validate_keys(obj)
|
262
|
+
return nil unless @required
|
263
|
+
|
264
|
+
keys = obj.keys
|
265
|
+
[].tap do |errors|
|
266
|
+
@required.each { |r| errors << r unless keys.include?(r) }
|
267
|
+
raise "Missing keys: #{errors.join(' ')}" unless errors.empty?
|
238
268
|
end
|
239
269
|
end
|
240
270
|
|
data/lib/luca_record/version.rb
CHANGED
data/lib/luca_support/code.rb
CHANGED
@@ -97,7 +97,7 @@ module LucaSupport
|
|
97
97
|
#
|
98
98
|
def take_current(dat, item)
|
99
99
|
target = dat.dig(item)
|
100
|
-
if target.
|
100
|
+
if target.is_a?(Array) && target.map(&:keys).flatten.include?('effective')
|
101
101
|
latest = target
|
102
102
|
.filter { |a| Date.parse(a.dig('effective').to_s) < @date }
|
103
103
|
.max { |a, b| Date.parse(a.dig('effective').to_s) <=> Date.parse(b.dig('effective').to_s) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucarecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|