lucarecord 0.7.4 → 0.8.1

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: ab8d42ca9b608b1523b0cf5cdf85ace0795c2852c0e7abb840c7ab63c6cf10d8
4
- data.tar.gz: 7fbd74937cbcacf501a5be5296eaa586162a3646817cd46d6f973fe6740db93e
3
+ metadata.gz: 43e4eb24c71ea14be0af8bcaa20ff15806b3f13fde5d9b0766f4554c725354e0
4
+ data.tar.gz: 76a9001610ac76dcb2904c500bce4283ce57612e6f7ac0d42da76f818eadf05a
5
5
  SHA512:
6
- metadata.gz: cef169faf34676d409b44d1b40ac5ae671f9e53ff0f4900ce42734a04ba98573ae906eb51cd95798bed89e2d74a4c5189e032b60ae390fdb442130572451278d
7
- data.tar.gz: 61b8f6864ae81c2f7b90540e019be72f3be41b835274cca6fe84c9014d00126167b8d7d5b7fb08aa445fc5562fd4edf61a3fe359218d1e24b1a72b17133a9b3d
6
+ metadata.gz: 493c82233012f4db8e001a04c65d8b010979835e61d04d6f6c0659de6b0557fef8085efa433748f63fdb02548943020a6574caaca24a2663d58eee8e5cad5235
7
+ data.tar.gz: 458ebf81b4639ec305e6b99cd0ebbfe3617d46538487a9cf781cdb32f3ca483b02b9c90de746457ddfc26d80e26a4169e688796beb0367b788df532d465d36e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## LucaRecord 0.8.1
2
+
3
+ * Merge config in parent directory, when the parent is git repo root.
4
+ * initial mTLS support for SMTP.
5
+ * change deprecated nushell option `--ignore-errors` -> `--optional`.
6
+
7
+ ## LucaRecord 0.8.0
8
+
9
+ * Expand SMTP options aligning with mail gem.
10
+
11
+ ## LucaRecord 0.7.5
12
+
13
+ * `LucaSupport::Code.parse_current() / take_current()` now accepts Date object.
14
+
1
15
  ## LucaRecord 0.7.4
2
16
 
3
17
  * `LucaSupport::ENC.encrypt() / decrypt()` use env `LUCA_ENC_PASSWORD` for automation.
@@ -78,7 +78,7 @@ module LucaRecord
78
78
  end
79
79
  end
80
80
 
81
- # generate dictionary from TSV file. Minimum assumption is as bellows:
81
+ # generate dictionary from TSV file. Minimum assumption is:
82
82
  # 1st row is converted symbol.
83
83
  #
84
84
  # * row[0] is 'code'. Converted hash keys
@@ -297,25 +297,7 @@ module LucaRecord # :nodoc:
297
297
  config = {
298
298
  'decimal_separator' => '.',
299
299
  'thousands_separator' => ','
300
- }
301
- begin
302
- config.merge!(YAML.safe_load(
303
- File.read(Pathname(CONST.configdir) / 'config.yml'),
304
- permitted_classes: [Date]
305
- ))
306
- rescue Errno::ENOENT
307
- STDERR.puts "INFO: config.yml not found. Continue with default settings."
308
- end
309
- if ext_conf
310
- begin
311
- config.merge!(YAML.safe_load(
312
- File.read(Pathname(CONST.configdir) / ext_conf),
313
- permitted_classes: [Date]
314
- ))
315
- rescue Errno::ENOENT
316
- STDERR.puts "WARN: #{ext_conf} not found. Extended options are not effective."
317
- end
318
- end
300
+ }.merge!(load_config(CONST.configdir, ext_conf: ext_conf))
319
301
  config['decimal_num'] ||= config['country'] == 'jp' ? 0 : 2
320
302
  CONST.set_config(config)
321
303
  end
@@ -341,6 +323,62 @@ module LucaRecord # :nodoc:
341
323
  digest
342
324
  end
343
325
 
326
+ def load_config(path = nil, ext_conf: nil)
327
+ dir, file = if (filepath = Pathname(path)).file?
328
+ [filepath.dirname, filepath]
329
+ elsif filepath.directory?
330
+ [filepath, filepath / 'config.yml']
331
+ else
332
+ nil
333
+ end
334
+ return {} if dir.nil?
335
+
336
+ {}.tap do |config|
337
+ begin
338
+ if ! dir.join('.git').exist? \
339
+ && (parent = dir.parent).join('.git/objects').directory? \
340
+ && (parent_config = parent.join('config.yml')).file?
341
+ config.merge!(YAML.safe_load(
342
+ parent_config.read,
343
+ permitted_classes: [Date]
344
+ ))
345
+ end
346
+ end
347
+ begin
348
+ part = YAML.safe_load(
349
+ file.read,
350
+ permitted_classes: [Date]
351
+ )
352
+ config.merge!(part) do |_k, v_self, v_new|
353
+ if v_self.is_a? Hash
354
+ v_self.merge(v_new)
355
+ else
356
+ v_new
357
+ end
358
+ end
359
+ rescue Errno::ENOENT
360
+ STDERR.puts "INFO: #{file} not found. Continue with default settings."
361
+ end
362
+ if ext_conf
363
+ begin
364
+ part = YAML.safe_load(
365
+ (Pathname(CONST.configdir) / ext_conf).read,
366
+ permitted_classes: [Date]
367
+ )
368
+ config.merge!(part) do |_k, v_self, v_new|
369
+ if v_self.is_a? Hash
370
+ v_self.merge(v_new)
371
+ else
372
+ v_new
373
+ end
374
+ rescue Errno::ENOENT
375
+ STDERR.puts "WARN: #{ext_conf} not found. Extended options are not effective."
376
+ end
377
+ end
378
+ end
379
+ end
380
+ end
381
+
344
382
  private
345
383
 
346
384
  # define new transaction ID & write data at once
@@ -372,7 +410,7 @@ module LucaRecord # :nodoc:
372
410
  # '2020': All month of 2020
373
411
  # '2020[FG]': June & July of 2020
374
412
  #
375
- # Block will receive code fragments as 2nd parameter. Array format is as bellows:
413
+ # Block will receive code fragments as 2nd parameter. Array format is:
376
414
  # 1. encoded month
377
415
  # 2. encoded day + record number of the day
378
416
  # 3. codes. More than 3 are all code set except first 2 parameters.
@@ -532,14 +570,5 @@ module LucaRecord # :nodoc:
532
570
  end
533
571
  end
534
572
  end
535
-
536
- def load_config(path = nil)
537
- path = path.to_s
538
- if File.exist?(path)
539
- YAML.safe_load(File.read(path), permitted_classes: [Date])
540
- else
541
- {}
542
- end
543
- end
544
573
  end
545
574
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.7.4'
4
+ VERSION = '0.8.1'
5
5
  end
@@ -183,14 +183,14 @@ module LucaSupport # :nodoc:
183
183
  # convert effective/defunct data into current hash on @date.
184
184
  # not parse nested children.
185
185
  #
186
- def parse_current(dat)
186
+ def parse_current(dat, date = @date)
187
187
  {}.tap do |processed|
188
- dat.each { |k, _v| processed[k] = take_current(dat, k) }
188
+ dat.each { |k, _v| processed[k] = take_current(dat, k, date) }
189
189
  end
190
190
  end
191
191
 
192
192
  # return current value with effective/defunct on target @date
193
- # For multiple attribues, return hash on other than 'val'. Examples are as bellows:
193
+ # For multiple attribues, return hash on other than 'val'. Examples:
194
194
  #
195
195
  # - effective: 2020-1-1
196
196
  # val: 3000
@@ -205,7 +205,7 @@ module LucaSupport # :nodoc:
205
205
  # val: 3000
206
206
  # => nil
207
207
  #
208
- def take_current(dat, item)
208
+ def take_current(dat, item, date = @date)
209
209
  target = dat&.dig(item)
210
210
  return target unless target.is_a?(Array)
211
211
 
@@ -213,8 +213,8 @@ module LucaSupport # :nodoc:
213
213
  return target if !keys.include?('effective') && !keys.include?('defunct')
214
214
 
215
215
  latest = target
216
- .reject { |a| a['defunct'] && Date.parse(a['defunct'].to_s) < @date }
217
- .filter { |a| a['effective'] && Date.parse(a['effective'].to_s) < @date }
216
+ .reject { |a| a['defunct'] && Date.parse(a['defunct'].to_s) < date }
217
+ .filter { |a| a['effective'] && Date.parse(a['effective'].to_s) < date }
218
218
  .max { |a, b| Date.parse(a['effective'].to_s) <=> Date.parse(b['effective'].to_s) }
219
219
 
220
220
  latest&.dig('val') || latest
@@ -1,4 +1,6 @@
1
1
  require "mail"
2
+ require 'net/smtp'
3
+ require 'openssl'
2
4
  require "pathname"
3
5
  require "luca_record/io"
4
6
 
@@ -8,7 +10,7 @@ module LucaSupport
8
10
 
9
11
  def initialize(mail=nil, pjdir=nil)
10
12
  @pjdir = pjdir || Dir.pwd
11
- @config = load_config( Pathname(@pjdir) + "config.yml" )
13
+ @config = self.class.load_config(@pjdir)
12
14
  @mail = mail
13
15
  set_message_default
14
16
  @host = set_host
@@ -16,18 +18,26 @@ module LucaSupport
16
18
 
17
19
  def deliver
18
20
  # mail gem accepts hash for 2nd param, not keywords
19
- @mail.delivery_method(:smtp, @host)
21
+ if conn = conn_with_tls
22
+ @mail.delivery_method(:smtp_connection, { connection: conn })
23
+ else
24
+ @mail.delivery_method(:smtp, @host)
25
+ end
20
26
  @mail.deliver
21
27
  end
22
28
 
23
29
  def set_host
24
30
  {
25
- authentication: :plain,
26
31
  address: mail_config("address"),
27
32
  port: mail_config("port"),
28
- doomain: mail_config("domain"),
33
+ domain: mail_config("domain"),
29
34
  user_name: mail_config("user_name"),
30
- password: mail_config("password")
35
+ password: mail_config("password"),
36
+ authentication: mail_config("authentication"),
37
+ enable_starttls: mail_config("enable_starttls"),
38
+ openssl_verify_mode: mail_config("openssl_verify_mode"),
39
+ ssl: mail_config("ssl"),
40
+ tls: mail_config("tls"),
31
41
  }
32
42
  end
33
43
 
@@ -40,5 +50,28 @@ module LucaSupport
40
50
  @mail.from ||= @config.dig("mail", "from")
41
51
  @mail.cc ||= @config.dig("mail", "cc")
42
52
  end
53
+
54
+ private
55
+
56
+ def conn_with_tls
57
+ ca_file = mail_config("ca_file")
58
+ c_cert_path = mail_config("client_cert")
59
+ c_key_path = mail_config("client_key")
60
+ return nil if ca_file.nil? && c_cert_path.nil? && c_key_path.nil?
61
+
62
+ tls_ctx = OpenSSL::SSL::SSLContext.new
63
+ tls_ctx.cert = c_cert_path ?
64
+ OpenSSL::X509::Certificate.new(File.read(c_cert_path)) : nil
65
+ tls_ctx.key = c_key_path ?
66
+ OpenSSL::PKey::RSA.new(File.read(c_key_path)) : nil
67
+ tls_ctx.ca_file = ca_file
68
+ tls_ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER if ca_file || @host[:openssl_verify_mode]
69
+
70
+ conn = Net::SMTP.new(@host[:address], @host[:port])
71
+ conn.enable_tls(tls_ctx)
72
+ conn.start(helo: @host[:domain], user: @host[:user_name], password: @host[:password], authtype: @host[:authentication])
73
+ conn
74
+ end
75
+
43
76
  end
44
77
  end
@@ -58,7 +58,7 @@ module LucaSupport
58
58
  select = if columns.empty?
59
59
  ''
60
60
  else
61
- '| select --ignore-errors ' + columns.map { |col| col.gsub(/[^a-zA-Z0-9_-]/, '') }.join(' ')
61
+ '| select --optional ' + columns.map { |col| col.gsub(/[^a-zA-Z0-9_-]/, '') }.join(' ')
62
62
  end
63
63
  render = case mode
64
64
  when :explore
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.7.4
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-13 00:00:00.000000000 Z
11
+ date: 2025-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,7 +78,7 @@ files:
78
78
  - lib/luca_support/view.rb
79
79
  homepage: https://github.com/chumaltd/luca/tree/master/lucarecord
80
80
  licenses:
81
- - GPL
81
+ - GPL-3.0-or-later
82
82
  metadata:
83
83
  homepage_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
84
84
  source_code_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.4.10
101
+ rubygems_version: 3.4.20
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: ERP File operation framework