lucarecord 0.5.4 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/luca_record/io.rb +11 -8
- data/lib/luca_record/version.rb +1 -1
- data/lib/luca_support/code.rb +12 -1
- data/lib/luca_support/view.rb +13 -2
- 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: a8292ffede60ef44ad0ff29a395e29f957d9c10214b0c3aedbb09dc8079bb502
|
4
|
+
data.tar.gz: da00267ca8e4884c5e14ec23923be391043afb1aa169409be1f08009b15cbc7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a08fd4e4a5d009273127e05105dcee05783f1df107c9296cf2ba64146f5ce61952d51817a1fc41c7dd1adab327ca825e3c67471f2f93eb0541c74037fa2269d
|
7
|
+
data.tar.gz: 1b26ae61830565c856b2ff41220236caffbefb4015c4a483f77f4c15aaa3ac6caab85ebb3b1c0e0d8f669e92d5ec0c37ffe4bb69f773cc8e4771f8598710589a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## LucaRecord 0.5.6
|
2
|
+
|
3
|
+
* add Nushell render mode: expand(default) | collapse | explore(`less` like)
|
4
|
+
* add `LucaSupport::Code.take_history()`, listing all effective/defunct values.
|
5
|
+
|
6
|
+
## LucaRecord 0.5.5
|
7
|
+
|
8
|
+
* support JSON for `LucaRecord::Base.load_data()` w/ `@record_type = 'json'`
|
9
|
+
|
1
10
|
## LucaRecord 0.5.4
|
2
11
|
|
3
12
|
* add `upsert()`
|
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'
|
@@ -427,14 +428,16 @@ module LucaRecord # :nodoc:
|
|
427
428
|
# If specific decode is needed, override this method in each class.
|
428
429
|
#
|
429
430
|
def load_data(io, path = nil)
|
430
|
-
if @record_type
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
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) }
|
438
441
|
end
|
439
442
|
|
440
443
|
def validate_keys(obj)
|
data/lib/luca_record/version.rb
CHANGED
data/lib/luca_support/code.rb
CHANGED
@@ -180,7 +180,6 @@ module LucaSupport # :nodoc:
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
#
|
184
183
|
# convert effective/defunct data into current hash on @date.
|
185
184
|
# not parse nested children.
|
186
185
|
#
|
@@ -221,6 +220,18 @@ module LucaSupport # :nodoc:
|
|
221
220
|
latest&.dig('val') || latest
|
222
221
|
end
|
223
222
|
|
223
|
+
# convert all effective/defunct data into Array
|
224
|
+
# not parse nested children.
|
225
|
+
#
|
226
|
+
def take_history(dat, item)
|
227
|
+
target = dat&.dig(item)
|
228
|
+
return Array(target) unless target.is_a?(Array)
|
229
|
+
|
230
|
+
target
|
231
|
+
.sort { |a, b| Date.parse(a['effective'].to_s) <=> Date.parse(b['effective'].to_s) }
|
232
|
+
.map { |a| a['val'] }
|
233
|
+
end
|
234
|
+
|
224
235
|
def has_status?(dat, status)
|
225
236
|
return false if dat['status'].nil?
|
226
237
|
|
data/lib/luca_support/view.rb
CHANGED
@@ -48,7 +48,10 @@ module LucaSupport
|
|
48
48
|
nil
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
# render mode swithes nushell Viewer
|
52
|
+
# https://www.nushell.sh/commands/categories/viewers.html
|
53
|
+
#
|
54
|
+
def nushell(records, mode=:expand, columns=[])
|
52
55
|
return nil if records.is_a?(String)
|
53
56
|
|
54
57
|
require 'open3'
|
@@ -57,7 +60,15 @@ module LucaSupport
|
|
57
60
|
else
|
58
61
|
'| select --ignore-errors ' + columns.map { |col| col.gsub(/[^a-zA-Z0-9_-]/, '') }.join(' ')
|
59
62
|
end
|
60
|
-
|
63
|
+
render = case mode
|
64
|
+
when :explore
|
65
|
+
'explore'
|
66
|
+
when :collapse
|
67
|
+
'table -c'
|
68
|
+
else
|
69
|
+
'table -e'
|
70
|
+
end
|
71
|
+
Open3.pipeline_w(%(nu -c 'cat - | from json #{select} | #{render}')) { |stdin| stdin.puts JSON.dump(records) }
|
61
72
|
end
|
62
73
|
end
|
63
74
|
end
|
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.6
|
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-04-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|