lucarecord 0.7.1 → 0.7.3

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: 75aa7ba67a42741a9b533dcdbd83a52a3a9d4d113b8bdb558d894d39cdab453b
4
- data.tar.gz: 1f80272124518bfdf0f8f2461e8e5f24a2d60ca5bffa1c4f06e386b5f5b966d3
3
+ metadata.gz: 69e3e577310289d8d99054cbfa806d62650fa25263fc3f832381cae085af123e
4
+ data.tar.gz: 933a159f84ef1118223297727a028e15db9ca1d82dc40b2410051f05edf44977
5
5
  SHA512:
6
- metadata.gz: b18fe1bb5b4094d76330adb36445c673941f4b75987657029c72fb987bbc1b64dd405623bb6b4a1636288c7f3054bf02cdb0e77a1161b761d6b7e5e4510e8663
7
- data.tar.gz: 0eb7fda772606eec3019b08fcaccc89c99b17fb9d52169c7c31b529ac70fbd16c18a6b305dc95acc29dfee04f22f14381ee8302b081c4e26d4f3c352c45df87e
6
+ metadata.gz: e2bcd328ef856b99970549f9405ea5b0c89f91a5ecfa4877b7304180bd9096f4e5c5595f0fe0b94e5b4ac67e904f830157f5678ce95442e89df7220ad6c52939
7
+ data.tar.gz: c2caec75adf8894cb97fcb5eec66474f6235ead40666d214c24471b21e9b89aea9c94898df17e72e8cdbb397f6af0fb5458ac2c926f6297a038fe1de33d6f2ae
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## LucaRecord 0.7.3
2
+
3
+ * 'config/' inside the project data dir is now used as a primary configuration dir.
4
+ * Without config files, it continues to work with warnings instead of aborts.
5
+
6
+ ## LucaRecord 0.7.2
7
+
8
+ * `LucaCmd.check_dir()` accepts optional `ext_conf:` keyword.
9
+
1
10
  ## LucaRecord 0.7.1
2
11
 
3
12
  * `LucaRecord::IO.load_project()` supports optional `ext_conf:` keyword for an extra config file.
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)
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
- LucaRecord::Base.load_project(Dir.pwd)
15
- LucaRecord::Base.valid_project?
24
+ LucaRecord::Base.load_project(Dir.pwd, ext_conf: ext_conf)
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.1'
4
+ VERSION = '0.7.3'
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucarecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro