lucarecord 0.5.3 → 0.5.4

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: cf1f2de4d31ac30fa0e7e2a54d2391c04a0aec3008f0d141fd5d887b39f1e8eb
4
- data.tar.gz: f50d14c026db0bd94007bff1e35ab0ff65b6e6a34f97ce282fa8b2dd53adc909
3
+ metadata.gz: d7a1835b0493134002d92d7a9b8f8fb6a55305f470636c448da8848f9b6afdaa
4
+ data.tar.gz: 9ec15acf15451babe4280c098e670f68a377e9be9af8e312f3b0b558476da995
5
5
  SHA512:
6
- metadata.gz: 152215ed2b331ea30afc08b137b938231d6b40c3254bc8ea99f6cb540bba5727cf3e7b043b5002872ce8c814716c266a2f6f536880f2fdb01d674af6da1e76c7
7
- data.tar.gz: 951a08656f3f50e95d58ad724c5f998f23e34d45c8453e79ff297ba059e4ed9e9f176455c1f335d8ed1a52e7545fbb7c5224a1a5862af81c4072ae4c66ac6900
6
+ metadata.gz: 7741483aa8e7e6ca1fb01325f546e703b4a530d48b7d68823f127402c39a092d01ee1bcc6a2f319794bd0830a7095957405b833f02c11e480fec6df399f37997
7
+ data.tar.gz: 90934508dd586dc6582be9366b22d9a60958ce247c0d971d36207016b5ec5b69ee7375f6613cc7e37fe920fd135c2fd85dd5482458763e9372b7ae0c39bf78e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  ## LucaRecord 0.5.3
2
10
 
3
11
  * add `find_secure()` for partial data encryption.
@@ -148,6 +148,26 @@ module LucaRecord # :nodoc:
148
148
  end
149
149
  end
150
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
+
151
171
  # If multiple ID matched, return short ID and human readable label.
152
172
  #
153
173
  def id_completion(phrase, label: 'name', basedir: @dirname)
@@ -333,7 +353,16 @@ module LucaRecord # :nodoc:
333
353
  file_pattern = filename.nil? ? '*' : "#{filename}*"
334
354
  Dir.chdir(abs_path(basedir)) do
335
355
  FileUtils.mkdir_p(subdir) if mode == 'w' && !Dir.exist?(subdir)
336
- Dir.glob("#{subdir}*/#{file_pattern}").sort.each do |subpath|
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)
337
366
  next if skip_on_unmatch_code(subpath, code)
338
367
 
339
368
  id_set = subpath.split('/').map { |str| str.split('-') }.flatten
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.5.3'
4
+ VERSION = '0.5.4'
5
5
  end
@@ -153,6 +153,7 @@ module LucaSupport # :nodoc:
153
153
  when 'Integer'
154
154
  BigDecimal(obj.to_s)
155
155
  when 'String'
156
+ return obj if /^0[0-9]+$/.match(obj) # zero-prefixed code
156
157
  /^[0-9\.]+$/.match(obj) ? BigDecimal(obj) : obj
157
158
  when 'Float'
158
159
  raise 'already float'
@@ -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
@@ -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(yml)
51
+ def nushell(records, columns=[])
52
+ return nil if records.is_a?(String)
53
+
51
54
  require 'open3'
52
- Open3.pipeline_w(%(nu -c 'cat - | from yaml')) { |stdin| stdin.puts yml }
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  module LucaSupport
4
4
  autoload :Code, 'luca_support/code'
5
+ autoload :Enc, 'luca_support/enc'
5
6
  autoload :CONFIG, 'luca_support/config'
6
7
  autoload :Config, 'luca_support/config'
7
8
  autoload :Mail, 'luca_support/mail'
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.3
4
+ version: 0.5.4
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-01-18 00:00:00.000000000 Z
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
@@ -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.4.1
100
+ rubygems_version: 3.3.5
100
101
  signing_key:
101
102
  specification_version: 4
102
103
  summary: ERP File operation framework