lucarecord 0.7.2 → 0.7.4

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: 48c2bb561dd877e5400caf8944563350b26d013164692fdccdb61d128a45312e
4
- data.tar.gz: 6b5a1e71c3a1b4f337ddfe967050e6443f05c246d07c51d360e0c6ea10955984
3
+ metadata.gz: ab8d42ca9b608b1523b0cf5cdf85ace0795c2852c0e7abb840c7ab63c6cf10d8
4
+ data.tar.gz: 7fbd74937cbcacf501a5be5296eaa586162a3646817cd46d6f973fe6740db93e
5
5
  SHA512:
6
- metadata.gz: 112755952657fbbf7463b8af6e942ae7598c0a905033f38bd99d07b5e5dfba124177f5a9c9f82aee6c0f4fdd920ea46637c4d8d7453d80b1fc852d93548ad4af
7
- data.tar.gz: 2598d1e49de40e1bd58abc5436c77291683a3a9704348ec8ba9764c6f8435148ee01b9f237297bc145e0459c16b19127f8e463fc352dfebd36af1e00e4039cec
6
+ metadata.gz: cef169faf34676d409b44d1b40ac5ae671f9e53ff0f4900ce42734a04ba98573ae906eb51cd95798bed89e2d74a4c5189e032b60ae390fdb442130572451278d
7
+ data.tar.gz: 61b8f6864ae81c2f7b90540e019be72f3be41b835274cca6fe84c9014d00126167b8d7d5b7fb08aa445fc5562fd4edf61a3fe359218d1e24b1a72b17133a9b3d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## LucaRecord 0.7.4
2
+
3
+ * `LucaSupport::ENC.encrypt() / decrypt()` use env `LUCA_ENC_PASSWORD` for automation.
4
+
5
+ ## LucaRecord 0.7.3
6
+
7
+ * 'config/' inside the project data dir is now used as a primary configuration dir.
8
+ * Without config files, it continues to work with warnings instead of aborts.
9
+
1
10
  ## LucaRecord 0.7.2
2
11
 
3
12
  * `LucaCmd.check_dir()` accepts optional `ext_conf:` keyword.
data/lib/luca_cmd.rb CHANGED
@@ -1,18 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
  require 'luca_record'
3
+ require 'pathname'
3
4
 
4
5
  class LucaCmd
5
- def self.check_dir(target, ext_conf: nil)
6
+ # Search app specific dir from pwd either in direct or monorepo configuration.
7
+ # 'config/' subdir has priority for consolidating shared config between apps.
8
+ #
9
+ def self.check_dir(essential_dir, ext_conf: nil)
10
+ if Dir.exist?('config')
11
+ LucaRecord::CONST.set_configdir(Pathname(Dir.pwd) / 'config')
12
+ end
6
13
  unless Dir.exist?('data')
7
14
  Dir.glob('*').reject { |f| File.symlink?(f) }
8
- .find { |f| File.directory?("#{f}/data/#{target}") }.tap do |d|
9
- abort "No valid data directory, exit..." if d.nil?
15
+ .find { |f| File.directory?("#{f}/data/#{essential_dir}") }.tap do |d|
16
+ abort "No valid data directory, exit..." if d.nil?
10
17
 
11
- Dir.chdir(d)
18
+ Dir.chdir(d)
19
+ if Dir.exist?('config')
20
+ LucaRecord::CONST.set_configdir(Pathname(Dir.pwd) / 'config')
12
21
  end
22
+ end
13
23
  end
14
24
  LucaRecord::Base.load_project(Dir.pwd, ext_conf: ext_conf)
15
- LucaRecord::Base.valid_project?
16
25
  yield
17
26
  end
18
27
  end
@@ -294,29 +294,36 @@ module LucaRecord # :nodoc:
294
294
 
295
295
  def load_project(path, ext_conf: nil)
296
296
  CONST.set_pjdir(path)
297
+ config = {
298
+ 'decimal_separator' => '.',
299
+ 'thousands_separator' => ','
300
+ }
297
301
  begin
298
- config = {
299
- 'decimal_separator' => '.',
300
- 'thousands_separator' => ','
301
- }.merge(YAML.safe_load(
302
- File.read(Pathname(CONST.pjdir) / 'config.yml'),
303
- permitted_classes: [Date]
304
- ))
305
- config['decimal_num'] ||= config['country'] == 'jp' ? 0 : 2
306
- if ext_conf
307
- config.merge(YAML.safe_load(
308
- File.read(Pathname(CONST.pjdir) / ext_conf),
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),
309
313
  permitted_classes: [Date]
310
314
  ))
315
+ rescue Errno::ENOENT
316
+ STDERR.puts "WARN: #{ext_conf} not found. Extended options are not effective."
311
317
  end
312
- CONST.set_config(config)
313
318
  end
319
+ config['decimal_num'] ||= config['country'] == 'jp' ? 0 : 2
320
+ CONST.set_config(config)
314
321
  end
315
322
 
316
323
  # test if having required dirs/files under exec path
317
324
  def valid_project?(path = CONST.pjdir)
318
325
  project_dir = Pathname(path)
319
- FileTest.file?((project_dir + 'config.yml').to_s) and FileTest.directory?( (project_dir + 'data').to_s)
326
+ FileTest.directory?( (project_dir / 'data').to_s)
320
327
  end
321
328
 
322
329
  def new_record_id(basedir, date_obj)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.7.2'
4
+ VERSION = '0.7.4'
5
5
  end
@@ -5,10 +5,11 @@ require 'singleton'
5
5
  module LucaSupport
6
6
  class ConstantHolder
7
7
  include Singleton
8
- attr_reader :config, :pjdir
8
+ attr_reader :config, :configdir, :pjdir
9
9
 
10
10
  def initialize
11
11
  @pjdir = ENV['LUCA_TEST_DIR']
12
+ @configdir = ENV['LUCA_TEST_DIR']
12
13
  @config = {
13
14
  'decimal_separator' => '.',
14
15
  'decimal_num' => 2,
@@ -18,6 +19,11 @@ module LucaSupport
18
19
 
19
20
  def set_pjdir(path)
20
21
  @pjdir ||= path
22
+ @configdir ||= path
23
+ end
24
+
25
+ def set_configdir(path)
26
+ @configdir = path
21
27
  end
22
28
 
23
29
  def set_config(config)
@@ -13,8 +13,11 @@ module LucaSupport # :nodoc:
13
13
  # TODO: check space in dir string
14
14
  # TODO: check if origin exists
15
15
  def encrypt(dir, iter: 10000, cleanup: false)
16
+ passopt = ENV['LUCA_ENC_PASSWORD'] ? "-pass pass:#{ENV['LUCA_ENC_PASSWORD']}" : ''
16
17
  Dir.chdir(Pathname(CONST.pjdir) / 'data') do
17
- system "tar -czf - #{dir} | openssl enc -e -aes256 -iter #{iter} -out #{dir}.tar.gz"
18
+ abort "Directory #{dir} not found. exit..." unless Dir.exist?(dir)
19
+
20
+ system "tar czf - #{dir} | openssl enc -e -aes256 -iter #{iter} -out #{dir}.tar.gz #{passopt}"
18
21
  return if ! cleanup
19
22
 
20
23
  FileUtils.rm_rf dir
@@ -23,8 +26,11 @@ module LucaSupport # :nodoc:
23
26
 
24
27
  # TODO: check space in dir string
25
28
  def decrypt(dir, iter: 10000)
29
+ passopt = ENV['LUCA_ENC_PASSWORD'] ? "-pass pass:#{ENV['LUCA_ENC_PASSWORD']}" : ''
26
30
  Dir.chdir(Pathname(CONST.pjdir) / 'data') do
27
- system "openssl enc -d -aes256 -iter #{iter} -in #{dir}.tar.gz | tar xz"
31
+ abort "Archive #{dir}.tar.gz not found. exit..." unless File.exist?("#{dir}.tar.gz")
32
+
33
+ system "openssl enc -d -aes256 -iter #{iter} -in #{dir}.tar.gz #{passopt} | tar xz"
28
34
  end
29
35
  end
30
36
  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.7.2
4
+ version: 0.7.4
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-11 00:00:00.000000000 Z
11
+ date: 2024-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler