lucarecord 0.2.24 → 0.2.25

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: 88e839f7ee18513f3798a568e65bd067eb16b87209f895f1b13a0deb43433837
4
- data.tar.gz: 9292a2d9a8e53cab0b5d4aabcea77f5a9a45f8fb504e048ac081a22e86b2ae28
3
+ metadata.gz: 1982b60b00eddc3d201368a2f436835fa51c6ba58538de3fcd0ce962c4529246
4
+ data.tar.gz: 894ef1778f5a8be1f2091575ec86e84ceb61d0d158ba0cb4b8bc297c7070593a
5
5
  SHA512:
6
- metadata.gz: b6d39c80ffea32406bd009cbd1c3393a8c02c52128ac6365f395ff68af2f1b8964aa1bdd2b7f951dab00aad00a3659bff2883dd839e3179bd013b8e1026185d5
7
- data.tar.gz: 8577ad3aee104dc8341b20ec04aae3f18a0145ca826165696f726cce4a2f25661c1205fb79ce2e43d5d361f7c89a449607f8854349c7ea0c6a6a987da1c3aaee
6
+ metadata.gz: 396bfbd54619361753b576fdda9f715b115ab274df10dce07abb1a5f180ed161946c72bae02c4926ff05d828e20af6920c689a412c71234c5baef072f870b528
7
+ data.tar.gz: 633d8920f547c893b2b1ac6645bdd108439d3568cfa3ec738c70ec61f1f658374e598bce0144a5a85142a15e4353d102e35b48ea84988f4dae06b0658a3952f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## LucaRecord 0.2.25
2
+
3
+ * Implement `dir_digest()` for data validation.
4
+ * support defunct without effective history record
5
+
1
6
  ## LucaRecord 0.2.24
2
7
 
3
8
  * Digit delimiter for `delimit_num` can be customized through `thousands_separator` and `decimal_separator` in config.yml.
@@ -252,6 +252,17 @@ module LucaRecord # :nodoc:
252
252
  LucaSupport::Code.encode_txid(new_record_no(basedir, date_obj))
253
253
  end
254
254
 
255
+ # Calculate md5sum under specific month directory.
256
+ #
257
+ def dir_digest(year, month, basedir = @dirname)
258
+ subdir = year.to_s + LucaSupport::Code.encode_month(month)
259
+ digest = String.new
260
+ open_records(basedir, subdir).each do |f, path|
261
+ digest = update_digest(digest, f.read, path[1])
262
+ end
263
+ digest
264
+ end
265
+
255
266
  private
256
267
 
257
268
  # define new transaction ID & write data at once
@@ -339,12 +350,14 @@ module LucaRecord # :nodoc:
339
350
  # If specific decode is needed, override this method in each class.
340
351
  #
341
352
  def load_data(io, path = nil)
342
- case @record_type
343
- when 'raw'
344
- # TODO: raw may be unneeded in favor of override
345
- io
346
- when 'json'
347
- # TODO: implement JSON parse
353
+ if @record_type
354
+ case @record_type
355
+ when 'raw'
356
+ # TODO: raw may be unneeded in favor of override
357
+ io
358
+ when 'json'
359
+ # TODO: implement JSON parse
360
+ end
348
361
  else
349
362
  LucaSupport::Code.decimalize(YAML.load(io.read)).tap { |obj| validate_keys(obj) }
350
363
  end
@@ -420,5 +433,13 @@ module LucaRecord # :nodoc:
420
433
  {}
421
434
  end
422
435
  end
436
+
437
+ # Calculate md5sum with original digest, file content and filename(optional).
438
+ #
439
+ def update_digest(digest, str, filename = nil)
440
+ str = filename.nil? ? str : filename + str
441
+ content = Digest::MD5.new.update(str).hexdigest
442
+ Digest::MD5.new.update(digest + content).hexdigest
443
+ end
423
444
  end
424
445
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.2.24'
4
+ VERSION = '0.2.25'
5
5
  end
@@ -59,18 +59,18 @@ module LucaSupport
59
59
  case num
60
60
  when BigDecimal
61
61
  if decimal == 0
62
- num.floor.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
63
- .gsub!(/\s/, delimiter)
62
+ num.floor.to_s.reverse!.gsub(/(\d{3})(?=\d)/, '\1 ').reverse!
63
+ .gsub(/\s/, delimiter)
64
64
  else
65
65
  fragments = num.floor(decimal).to_s('F').split('.')
66
- fragments[0].reverse!.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
67
- .gsub!(/\s/, delimiter)
66
+ fragments[0].reverse!.gsub!(/(\d{3})(?=\d)/, '\1 ')
67
+ fragments[0].reverse!.gsub!(/\s/, delimiter)
68
68
  fragments[1].gsub!(/(\d{3})(?=\d)/, '\1 ')
69
69
  fragments.join(LucaSupport::CONFIG['decimal_separator'])
70
70
  end
71
71
  else
72
- num.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1 ').reverse!
73
- .gsub!(/\s/, delimiter)
72
+ num.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1 ').reverse!
73
+ .gsub(/\s/, delimiter)
74
74
  end
75
75
  end
76
76
 
@@ -187,7 +187,6 @@ module LucaSupport
187
187
  end
188
188
  end
189
189
 
190
- #
191
190
  # return current value with effective/defunct on target @date
192
191
  # For multiple attribues, return hash on other than 'val'. Examples are as bellows:
193
192
  #
@@ -200,18 +199,23 @@ module LucaSupport
200
199
  # point: 1000
201
200
  # => { 'effective' => 2020-1-1, 'rank' => 5, 'point' => 1000 }
202
201
  #
202
+ # - defunct: 2020-1-1
203
+ # val: 3000
204
+ # => nil
205
+ #
203
206
  def take_current(dat, item)
204
- target = dat.dig(item)
205
- if target.is_a?(Array) && target.map(&:keys).flatten.include?('effective')
206
- latest = target
207
- .filter { |a| Date.parse(a.dig('effective').to_s) < @date }
208
- .max { |a, b| Date.parse(a.dig('effective').to_s) <=> Date.parse(b.dig('effective').to_s) }
209
- return nil if !latest.dig('defunct').nil? && Date.parse(latest.dig('defunct').to_s) < @date
210
-
211
- latest.dig('val') || latest
212
- else
213
- target
214
- end
207
+ target = dat&.dig(item)
208
+ return target unless target.is_a?(Array)
209
+
210
+ keys = target.map(&:keys).flatten
211
+ return target if !keys.include?('effective') && !keys.include?('defunct')
212
+
213
+ latest = target
214
+ .reject { |a| a['defunct'] && Date.parse(a['defunct'].to_s) < @date }
215
+ .filter { |a| a['effective'] && Date.parse(a['effective'].to_s) < @date }
216
+ .max { |a, b| Date.parse(a['effective'].to_s) <=> Date.parse(b['effective'].to_s) }
217
+
218
+ latest&.dig('val') || latest
215
219
  end
216
220
 
217
221
  def has_status?(dat, status)
@@ -34,6 +34,10 @@ module LucaSupport
34
34
  out
35
35
  end
36
36
 
37
+ # Search existing file and return path under:
38
+ # 1. 'templates/' in Project directory that data resides
39
+ # 2. 'templates/' in Library directory that calls LucaSupport::View#search_template
40
+ #
37
41
  def search_template(file, dir = 'templates')
38
42
  # TODO: load config
39
43
  [LucaSupport::PJDIR, lib_path].each do |base|
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.2.24
4
+ version: 0.2.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-29 00:00:00.000000000 Z
11
+ date: 2021-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.1.2
112
+ rubygems_version: 3.2.3
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: ERP File operation framework