lucarecord 0.2.27 → 0.4.0

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: 3e81c1ccc95c688bdfa2da3af37635324f1f744f1976b0dd3654514e2a1254b4
4
- data.tar.gz: 2ed07a97b4bca099f1eb7004476960c3c2a8da03d06ee7f4db6e48226294f431
3
+ metadata.gz: fde3b4057d40252d43320a4f55acae976faff31b608a71e66ebcfec0ad8c592a
4
+ data.tar.gz: 89764a7a57b4aff62e4a48a64a418b7f5991ab4f6d9358eb6ea1fc476f7d6b7e
5
5
  SHA512:
6
- metadata.gz: fcdd0ddae31a118c6532c872361535d89336fa712ba80395a10d5dda7a597c6300214ac2c1cdbab6782bd861d46e9da1e32c48e3fae182c33d63e78b0fcf7424
7
- data.tar.gz: 4ec6114ea0f761e7ca4f743fce6c2594cac704c0bb6a32082ba35cbc5b9c6e639ce421d13ccf33a46a5359a4030974ff85447133391641beb83d2efaab3e1a91
6
+ metadata.gz: b58faff8563d38ceeb1e632381ec67487a7fd3b38d7473998f36605a4bfdd2a9bcaab25471348fa63b7a30a8f1bacb3f917421b8a1bcdabe4fc985f93a7342a2
7
+ data.tar.gz: 2de6368ee308eb4c20ddfd97e93544f5d1d2ae3f3b45f7937d2ab925cbd82d03748332fa9d502e536ed3953028cdf6caa522d73f418e28a24bc45c45e74d16d0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## LucaRecord 0.4.0
2
+
3
+ * Replace YAML.load/load_file to YAML.safe_load for compatibility with Ruby 3.1
4
+
5
+ ## LucaRecord 0.3.0
6
+
7
+ * implement LucaRecord::IO.latest_month
8
+
9
+ ## LucaRecord 0.2.28
10
+
11
+ * implement LucaSupport::Range, handle #by_month enumeration between several months.
12
+ * @record_type = 'raw' is deprecated in favor of overriding LucaRecord::IO.load_data
13
+ * change code search from exact match to prefix match
14
+
15
+ ## LucaRecord 0.2.27
16
+
17
+ * Fix: update_digest
18
+
1
19
  ## LucaRecord 0.2.26
2
20
 
3
21
  * Support #dig / #search for TSV dictionary
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'csv'
4
+ require 'date'
4
5
  require 'fileutils'
5
6
  require 'yaml'
6
7
  require 'pathname'
@@ -71,7 +72,7 @@ module LucaRecord
71
72
  when '.tsv', '.csv'
72
73
  load_tsv_dict(dict_path(file))
73
74
  when '.yaml', '.yml'
74
- YAML.load_file(dict_path(file), **{})
75
+ YAML.safe_load(File.read(dict_path(file)), permitted_classes: [Date])
75
76
  else
76
77
  raise 'cannot load this filetype'
77
78
  end
@@ -64,11 +64,7 @@ module LucaRecord # :nodoc:
64
64
 
65
65
  LucaSupport::Code.encode_term(start_year, start_month, end_year, end_month).each do |subdir|
66
66
  open_records(basedir, subdir, nil, code) do |f, path|
67
- if @record_type == 'raw'
68
- yield f, path
69
- else
70
- yield load_data(f, path)
71
- end
67
+ yield load_data(f, path)
72
68
  end
73
69
  end
74
70
  end
@@ -80,11 +76,7 @@ module LucaRecord # :nodoc:
80
76
 
81
77
  subdir = year.to_s + LucaSupport::Code.encode_month(month)
82
78
  open_records(basedir, subdir, LucaSupport::Code.encode_date(day), code) do |f, path|
83
- if @record_type == 'raw'
84
- yield f, path
85
- else
86
- yield load_data(f, path), path
87
- end
79
+ yield load_data(f, path), path
88
80
  end
89
81
  end
90
82
 
@@ -98,6 +90,12 @@ module LucaRecord # :nodoc:
98
90
  end
99
91
  end
100
92
 
93
+ # [year, month] pair of the latest record
94
+ #
95
+ def latest_month(code = nil, basedir = @dirname)
96
+ LucaSupport::Code.decode_term(Dir.entries(abs_path(basedir)).max)
97
+ end
98
+
101
99
  # ----------------------------------------------------------------
102
100
  # :section: Write Methods
103
101
  # <tt>basedir</tt> is set by class instance variable <tt>@dirname</tt>
@@ -152,7 +150,7 @@ module LucaRecord # :nodoc:
152
150
 
153
151
  def add_status!(id, status, basedir = @dirname)
154
152
  path = abs_path(basedir) / id2path(id)
155
- origin = YAML.load_file(path, **{})
153
+ origin = YAML.safe_load(File.read(path), permitted_classes: [Date])
156
154
  newline = { status => DateTime.now.to_s }
157
155
  origin['status'] = [] if origin['status'].nil?
158
156
  origin['status'] << newline
@@ -360,14 +358,11 @@ module LucaRecord # :nodoc:
360
358
  def load_data(io, path = nil)
361
359
  if @record_type
362
360
  case @record_type
363
- when 'raw'
364
- # TODO: raw may be unneeded in favor of override
365
- io
366
361
  when 'json'
367
362
  # TODO: implement JSON parse
368
363
  end
369
364
  else
370
- LucaSupport::Code.decimalize(YAML.load(io.read)).tap { |obj| validate_keys(obj) }
365
+ LucaSupport::Code.decimalize(YAML.safe_load(io.read, permitted_classes: [Date])).tap { |obj| validate_keys(obj) }
371
366
  end
372
367
  end
373
368
 
@@ -386,14 +381,17 @@ module LucaRecord # :nodoc:
386
381
  Pathname(LucaSupport::PJDIR) / 'data' / base_dir
387
382
  end
388
383
 
389
- # true when file doesn't have record on code
390
- # false when file may have one
384
+ # True when file doesn't have record on code.
385
+ # False when file may have one.
386
+ # If filename doesn't record codes, always return false,
387
+ # so later check is required. This is partial optimization.
388
+ #
391
389
  def skip_on_unmatch_code(subpath, code = nil)
392
390
  # p filename.split('-')[1..-1]
393
391
  filename = subpath.split('/').last
394
392
  return false if code.nil? || filename.length <= 4
395
393
 
396
- !filename.split('-')[1..-1].include?(code)
394
+ filename.split('-')[1..-1].select { |fragment| /^#{code}/.match(fragment) }.empty?
397
395
  end
398
396
 
399
397
  # AUTO INCREMENT
@@ -436,7 +434,7 @@ module LucaRecord # :nodoc:
436
434
  def load_config(path = nil)
437
435
  path = path.to_s
438
436
  if File.exist?(path)
439
- YAML.load_file(path, **{})
437
+ YAML.safe_load(File.read(path), permitted_classes: [Date])
440
438
  else
441
439
  {}
442
440
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.2.27'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -5,8 +5,9 @@ require 'securerandom'
5
5
  require 'digest/sha1'
6
6
  require 'luca_support/config'
7
7
 
8
- # implement Luca IDs convention
9
- module LucaSupport
8
+ module LucaSupport # :nodoc:
9
+ # implement Luca IDs convention
10
+ #
10
11
  module Code
11
12
  module_function
12
13
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
3
4
  require 'pathname'
4
5
  require 'yaml'
5
6
 
@@ -11,7 +12,7 @@ module LucaSupport
11
12
  {
12
13
  'decimal_separator' => '.',
13
14
  'thousands_separator' => ','
14
- }.merge(YAML.load_file(Pathname(PJDIR) / 'config.yml'))
15
+ }.merge(YAML.safe_load(File.read(Pathname(PJDIR) / 'config.yml'), permitted_classes: [Date]))
15
16
  rescue Errno::ENOENT
16
17
  {
17
18
  'decimal_separator' => '.',
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucaSupport # :nodoc:
4
+ # Partial range operation
5
+ #
6
+ module Range
7
+ def self.included(klass) # :nodoc:
8
+ klass.extend ClassMethods
9
+ end
10
+
11
+ def by_month(step = nil, from: nil, to: nil)
12
+ return enum_for(:by_month, step, from: from, to: to) unless block_given?
13
+
14
+ from ||= @start_date
15
+ to ||= @end_date
16
+ self.class.term_by_month(from, to, step || 1).each do |date|
17
+ @cursor_start = date
18
+ @cursor_end = step.nil? ? date : [date.next_month(step - 1), to].min
19
+ yield @cursor_start, @cursor_end
20
+ end
21
+ end
22
+
23
+ module ClassMethods
24
+ def term_by_month(start_date, end_date, step = 1)
25
+ Enumerator.new do |yielder|
26
+ each_month = start_date
27
+ while each_month <= end_date
28
+ yielder << each_month
29
+ each_month = each_month.next_month(step)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ 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.2.27
4
+ version: 0.4.0
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: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: 12.3.3
69
69
  description: 'ERP File operation framework
70
70
 
71
- '
71
+ '
72
72
  email:
73
73
  - co.chuma@gmail.com
74
74
  executables: []
@@ -86,6 +86,7 @@ files:
86
86
  - lib/luca_support/code.rb
87
87
  - lib/luca_support/config.rb
88
88
  - lib/luca_support/mail.rb
89
+ - lib/luca_support/range.rb
89
90
  - lib/luca_support/view.rb
90
91
  homepage: https://github.com/chumaltd/luca/tree/master/lucarecord
91
92
  licenses:
@@ -94,7 +95,7 @@ metadata:
94
95
  homepage_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
95
96
  source_code_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
96
97
  changelog_uri: https://github.com/chumaltd/luca/tree/master/lucarecord/CHANGELOG.md
97
- post_install_message:
98
+ post_install_message:
98
99
  rdoc_options: []
99
100
  require_paths:
100
101
  - lib
@@ -109,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  requirements: []
112
- rubygems_version: 3.2.3
113
- signing_key:
113
+ rubygems_version: 3.2.5
114
+ signing_key:
114
115
  specification_version: 4
115
116
  summary: ERP File operation framework
116
117
  test_files: []