lucarecord 0.5.1 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/luca_record/io.rb +72 -1
- 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 +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7a1835b0493134002d92d7a9b8f8fb6a55305f470636c448da8848f9b6afdaa
|
4
|
+
data.tar.gz: 9ec15acf15451babe4280c098e670f68a377e9be9af8e312f3b0b558476da995
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7741483aa8e7e6ca1fb01325f546e703b4a530d48b7d68823f127402c39a092d01ee1bcc6a2f319794bd0830a7095957405b833f02c11e480fec6df399f37997
|
7
|
+
data.tar.gz: 90934508dd586dc6582be9366b22d9a60958ce247c0d971d36207016b5ec5b69ee7375f6613cc7e37fe920fd135c2fd85dd5482458763e9372b7ae0c39bf78e7
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## LucaRecord 0.5.4
|
2
|
+
|
3
|
+
* add `upsert()`
|
4
|
+
* `open_records()` supports git-like id sub directories
|
5
|
+
* Regard zero-prefixed code like '00123' as not BigDecimal but String on YAML load
|
6
|
+
* Add support table columns order to `LucaSupport::View.nushell()`
|
7
|
+
* Breaking change: `LucaSupport::View.nushell()` takes Ruby Array. YAML is not accepted anymore.
|
8
|
+
|
9
|
+
## LucaRecord 0.5.3
|
10
|
+
|
11
|
+
* add `find_secure()` for partial data encryption.
|
12
|
+
|
13
|
+
## LucaRecord 0.5.2
|
14
|
+
|
15
|
+
* add `update_record()` by `open_records()` id_set.
|
16
|
+
|
1
17
|
## LucaRecord 0.5.1
|
2
18
|
|
3
19
|
* add `--enable-local-file-access` option to `wkhtmltopdf` command.
|
data/lib/luca_record/io.rb
CHANGED
@@ -46,6 +46,37 @@ module LucaRecord # :nodoc:
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
# Merge 2 files under plain & prefixed dirs.
|
50
|
+
# prefixed contents will override duplicated keys.
|
51
|
+
# This function does not provide encryption/decryption.
|
52
|
+
#
|
53
|
+
def find_secure(id, basedir = @dirname, prefix = 's_')
|
54
|
+
if id.length >= 40
|
55
|
+
plain = open_hashed(basedir, id) do |f|
|
56
|
+
load_data(f)
|
57
|
+
end
|
58
|
+
secure = begin
|
59
|
+
open_hashed("#{prefix}#{basedir}", id) do |f|
|
60
|
+
load_data(f)
|
61
|
+
end
|
62
|
+
rescue
|
63
|
+
# No file exists, and so on.
|
64
|
+
{}
|
65
|
+
end
|
66
|
+
elsif id.length >= 7
|
67
|
+
parts = id.split('/')
|
68
|
+
plain = open_records(basedir, parts[0], parts[1]) do |f|
|
69
|
+
load_data(f)
|
70
|
+
end
|
71
|
+
secure = open_records("#{prefix}#{basedir}", parts[0], parts[1]) do |f|
|
72
|
+
load_data(f)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
raise 'specified id length is too short'
|
76
|
+
end
|
77
|
+
plain.merge(secure)
|
78
|
+
end
|
79
|
+
|
49
80
|
# search date based record.
|
50
81
|
#
|
51
82
|
# * data hash
|
@@ -117,6 +148,26 @@ module LucaRecord # :nodoc:
|
|
117
148
|
end
|
118
149
|
end
|
119
150
|
|
151
|
+
# update uuid keyed record based on 'id' field.
|
152
|
+
# If not found, just create
|
153
|
+
#
|
154
|
+
def upsert(obj, basedir: @dirname)
|
155
|
+
return nil if obj['id'].nil?
|
156
|
+
|
157
|
+
validate_keys(obj)
|
158
|
+
merged = begin
|
159
|
+
open_hashed(basedir, obj['id'], 'r') do |f|
|
160
|
+
load_data(f).merge(obj)
|
161
|
+
end
|
162
|
+
rescue
|
163
|
+
obj
|
164
|
+
end
|
165
|
+
open_hashed(basedir, obj['id'], 'w') do |f|
|
166
|
+
f.write(YAML.dump(LucaSupport::Code.readable(merged.sort.to_h)))
|
167
|
+
end
|
168
|
+
obj['id']
|
169
|
+
end
|
170
|
+
|
120
171
|
# If multiple ID matched, return short ID and human readable label.
|
121
172
|
#
|
122
173
|
def id_completion(phrase, label: 'name', basedir: @dirname)
|
@@ -302,7 +353,16 @@ module LucaRecord # :nodoc:
|
|
302
353
|
file_pattern = filename.nil? ? '*' : "#{filename}*"
|
303
354
|
Dir.chdir(abs_path(basedir)) do
|
304
355
|
FileUtils.mkdir_p(subdir) if mode == 'w' && !Dir.exist?(subdir)
|
305
|
-
Dir.glob("#{subdir}*/#{file_pattern}"
|
356
|
+
records = Dir.glob("#{subdir}*/#{file_pattern}", sort: false)
|
357
|
+
records = case records.find_index { |path| FileTest.file?(path) }
|
358
|
+
when nil
|
359
|
+
# TODO: file_pattern is not valid
|
360
|
+
Dir.glob("#{subdir}*/*/#{file_pattern}", sort: false)
|
361
|
+
else
|
362
|
+
records.sort
|
363
|
+
end
|
364
|
+
records.each do |subpath|
|
365
|
+
next if FileTest.directory?(subpath)
|
306
366
|
next if skip_on_unmatch_code(subpath, code)
|
307
367
|
|
308
368
|
id_set = subpath.split('/').map { |str| str.split('-') }.flatten
|
@@ -311,6 +371,17 @@ module LucaRecord # :nodoc:
|
|
311
371
|
end
|
312
372
|
end
|
313
373
|
|
374
|
+
# Write record with id_set supplied by open_records().
|
375
|
+
#
|
376
|
+
def update_record(basedir, id_set, content)
|
377
|
+
raise "path fragments are too short" if id_set.length < 2
|
378
|
+
|
379
|
+
::IO.write(
|
380
|
+
abs_path(basedir) / id_set[0] / id_set[1..-1].join('-'),
|
381
|
+
content
|
382
|
+
)
|
383
|
+
end
|
384
|
+
|
314
385
|
# Calculate md5sum with original digest, file content and filename(optional).
|
315
386
|
#
|
316
387
|
def update_digest(digest, str, filename = nil)
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-11 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
|
@@ -81,7 +82,7 @@ metadata:
|
|
81
82
|
homepage_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
|
82
83
|
source_code_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
|
83
84
|
changelog_uri: https://github.com/chumaltd/luca/tree/master/lucarecord/CHANGELOG.md
|
84
|
-
post_install_message:
|
85
|
+
post_install_message:
|
85
86
|
rdoc_options: []
|
86
87
|
require_paths:
|
87
88
|
- lib
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
100
|
rubygems_version: 3.3.5
|
100
|
-
signing_key:
|
101
|
+
signing_key:
|
101
102
|
specification_version: 4
|
102
103
|
summary: ERP File operation framework
|
103
104
|
test_files: []
|