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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7a1835b0493134002d92d7a9b8f8fb6a55305f470636c448da8848f9b6afdaa
4
- data.tar.gz: 9ec15acf15451babe4280c098e670f68a377e9be9af8e312f3b0b558476da995
3
+ metadata.gz: a8292ffede60ef44ad0ff29a395e29f957d9c10214b0c3aedbb09dc8079bb502
4
+ data.tar.gz: da00267ca8e4884c5e14ec23923be391043afb1aa169409be1f08009b15cbc7f
5
5
  SHA512:
6
- metadata.gz: 7741483aa8e7e6ca1fb01325f546e703b4a530d48b7d68823f127402c39a092d01ee1bcc6a2f319794bd0830a7095957405b833f02c11e480fec6df399f37997
7
- data.tar.gz: 90934508dd586dc6582be9366b22d9a60958ce247c0d971d36207016b5ec5b69ee7375f6613cc7e37fe920fd135c2fd85dd5482458763e9372b7ae0c39bf78e7
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()`
@@ -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
- case @record_type
432
- when 'json'
433
- # TODO: implement JSON parse
434
- end
435
- else
436
- LucaSupport::Code.decimalize(YAML.safe_load(io.read, permitted_classes: [Date])).tap { |obj| validate_keys(obj) }
437
- end
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.5.4'
4
+ VERSION = '0.5.6'
5
5
  end
@@ -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
 
@@ -48,7 +48,10 @@ module LucaSupport
48
48
  nil
49
49
  end
50
50
 
51
- def nushell(records, columns=[])
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
- Open3.pipeline_w(%(nu -c 'cat - | from json #{select}')) { |stdin| stdin.puts JSON.dump(records) }
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
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 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler