lucarecord 0.5.3 → 0.5.5
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 +12 -0
- data/lib/luca_record/io.rb +41 -9
- data/lib/luca_record/version.rb +1 -1
- data/lib/luca_support/code.rb +1 -0
- data/lib/luca_support/enc.rb +31 -0
- data/lib/luca_support/view.rb +10 -2
- data/lib/luca_support.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4574038ef165ecd098bd37897f77a16edb5917aa6c157ce45a005598bc540af2
|
4
|
+
data.tar.gz: a2f22d1d3c9899e3c84c7662cb8859794541e31cbd116eae343deb4d4db3e415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05dccaddb053508040dfab00cd9451b20b10d3a9b78a5317609ab8e71a548109cee9c4ff2579132f2e7380bb470d8639e6ddfb80ffdb23e324c2971e89d596d0
|
7
|
+
data.tar.gz: e33237c779d1450bd6c1b9a1c208382a8eda87848da74117b36bc973b93c44b965e1970d8eea60eb0d83698361406700c4dbe1480d511bc0130ece78cf7c6cf3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## LucaRecord 0.5.5
|
2
|
+
|
3
|
+
* support JSON for `LucaRecord::Base.load_data()` w/ `@record_type = 'json'`
|
4
|
+
|
5
|
+
## LucaRecord 0.5.4
|
6
|
+
|
7
|
+
* add `upsert()`
|
8
|
+
* `open_records()` supports git-like id sub directories
|
9
|
+
* Regard zero-prefixed code like '00123' as not BigDecimal but String on YAML load
|
10
|
+
* Add support table columns order to `LucaSupport::View.nushell()`
|
11
|
+
* Breaking change: `LucaSupport::View.nushell()` takes Ruby Array. YAML is not accepted anymore.
|
12
|
+
|
1
13
|
## LucaRecord 0.5.3
|
2
14
|
|
3
15
|
* add `find_secure()` for partial data encryption.
|
data/lib/luca_record/io.rb
CHANGED
@@ -4,6 +4,7 @@ require 'bigdecimal'
|
|
4
4
|
require 'csv'
|
5
5
|
require 'date'
|
6
6
|
require 'fileutils'
|
7
|
+
require 'json'
|
7
8
|
require 'yaml'
|
8
9
|
require 'pathname'
|
9
10
|
require 'luca_support/code'
|
@@ -148,6 +149,26 @@ module LucaRecord # :nodoc:
|
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
152
|
+
# update uuid keyed record based on 'id' field.
|
153
|
+
# If not found, just create
|
154
|
+
#
|
155
|
+
def upsert(obj, basedir: @dirname)
|
156
|
+
return nil if obj['id'].nil?
|
157
|
+
|
158
|
+
validate_keys(obj)
|
159
|
+
merged = begin
|
160
|
+
open_hashed(basedir, obj['id'], 'r') do |f|
|
161
|
+
load_data(f).merge(obj)
|
162
|
+
end
|
163
|
+
rescue
|
164
|
+
obj
|
165
|
+
end
|
166
|
+
open_hashed(basedir, obj['id'], 'w') do |f|
|
167
|
+
f.write(YAML.dump(LucaSupport::Code.readable(merged.sort.to_h)))
|
168
|
+
end
|
169
|
+
obj['id']
|
170
|
+
end
|
171
|
+
|
151
172
|
# If multiple ID matched, return short ID and human readable label.
|
152
173
|
#
|
153
174
|
def id_completion(phrase, label: 'name', basedir: @dirname)
|
@@ -333,7 +354,16 @@ module LucaRecord # :nodoc:
|
|
333
354
|
file_pattern = filename.nil? ? '*' : "#{filename}*"
|
334
355
|
Dir.chdir(abs_path(basedir)) do
|
335
356
|
FileUtils.mkdir_p(subdir) if mode == 'w' && !Dir.exist?(subdir)
|
336
|
-
Dir.glob("#{subdir}*/#{file_pattern}"
|
357
|
+
records = Dir.glob("#{subdir}*/#{file_pattern}", sort: false)
|
358
|
+
records = case records.find_index { |path| FileTest.file?(path) }
|
359
|
+
when nil
|
360
|
+
# TODO: file_pattern is not valid
|
361
|
+
Dir.glob("#{subdir}*/*/#{file_pattern}", sort: false)
|
362
|
+
else
|
363
|
+
records.sort
|
364
|
+
end
|
365
|
+
records.each do |subpath|
|
366
|
+
next if FileTest.directory?(subpath)
|
337
367
|
next if skip_on_unmatch_code(subpath, code)
|
338
368
|
|
339
369
|
id_set = subpath.split('/').map { |str| str.split('-') }.flatten
|
@@ -398,14 +428,16 @@ module LucaRecord # :nodoc:
|
|
398
428
|
# If specific decode is needed, override this method in each class.
|
399
429
|
#
|
400
430
|
def load_data(io, path = nil)
|
401
|
-
if @record_type
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
431
|
+
raw_obj = if @record_type
|
432
|
+
case @record_type
|
433
|
+
when 'json'
|
434
|
+
JSON.parse(io.read)
|
435
|
+
end
|
436
|
+
else
|
437
|
+
YAML.safe_load(io.read, permitted_classes: [Date])
|
438
|
+
end
|
439
|
+
LucaSupport::Code.decimalize(raw_obj)
|
440
|
+
.tap { |obj| validate_keys(obj) }
|
409
441
|
end
|
410
442
|
|
411
443
|
def validate_keys(obj)
|
data/lib/luca_record/version.rb
CHANGED
data/lib/luca_support/code.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module LucaSupport # :nodoc:
|
6
|
+
# Encrypt/Decrypt directory with openssl command
|
7
|
+
#
|
8
|
+
module Enc
|
9
|
+
module_function
|
10
|
+
|
11
|
+
# TODO: check if openssl/tar exists
|
12
|
+
# TODO: handle multiple directories
|
13
|
+
# TODO: check space in dir string
|
14
|
+
# TODO: check if origin exists
|
15
|
+
def encrypt(dir, iter: 10000, cleanup: false)
|
16
|
+
Dir.chdir(Pathname(PJDIR) / 'data') do
|
17
|
+
system "tar -czf - #{dir} | openssl enc -e -aes256 -iter #{iter} -out #{dir}.tar.gz"
|
18
|
+
return if ! cleanup
|
19
|
+
|
20
|
+
FileUtils.rm_rf dir
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO: check space in dir string
|
25
|
+
def decrypt(dir, iter: 10000)
|
26
|
+
Dir.chdir(Pathname(PJDIR) / 'data') do
|
27
|
+
system "openssl enc -d -aes256 -iter #{iter} -in #{dir}.tar.gz | tar xz"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/luca_support/view.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'erb'
|
4
|
+
require 'json'
|
4
5
|
require 'open3'
|
5
6
|
require 'pathname'
|
6
7
|
|
@@ -47,9 +48,16 @@ module LucaSupport
|
|
47
48
|
nil
|
48
49
|
end
|
49
50
|
|
50
|
-
def nushell(
|
51
|
+
def nushell(records, columns=[])
|
52
|
+
return nil if records.is_a?(String)
|
53
|
+
|
51
54
|
require 'open3'
|
52
|
-
|
55
|
+
select = if columns.empty?
|
56
|
+
''
|
57
|
+
else
|
58
|
+
'| select --ignore-errors ' + columns.map { |col| col.gsub(/[^a-zA-Z0-9_-]/, '') }.join(' ')
|
59
|
+
end
|
60
|
+
Open3.pipeline_w(%(nu -c 'cat - | from json #{select}')) { |stdin| stdin.puts JSON.dump(records) }
|
53
61
|
end
|
54
62
|
end
|
55
63
|
end
|
data/lib/luca_support.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/luca_support.rb
|
72
72
|
- lib/luca_support/code.rb
|
73
73
|
- lib/luca_support/config.rb
|
74
|
+
- lib/luca_support/enc.rb
|
74
75
|
- lib/luca_support/mail.rb
|
75
76
|
- lib/luca_support/range.rb
|
76
77
|
- lib/luca_support/view.rb
|
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
- !ruby/object:Gem::Version
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
100
|
+
rubygems_version: 3.3.5
|
100
101
|
signing_key:
|
101
102
|
specification_version: 4
|
102
103
|
summary: ERP File operation framework
|