lucarecord 0.6.0 → 0.7.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: 0aa1cebca92730baae88aed3eae85d0d2c2d78c546a77fed3f1c938f17d9bebd
4
- data.tar.gz: dfba788f46016596ae050dc2c742428ee676fead174c3825841381c03b24e62f
3
+ metadata.gz: acbbdd5bec6e0582ecfae94fa619d0da6bb2f8de44a278ecb007837262e714bc
4
+ data.tar.gz: ac27f73dace69080863366d1d9dc65f0452df6ee83a9e2041db53afdd08ab6f4
5
5
  SHA512:
6
- metadata.gz: c63971e223278d08e688f96d791b517a84f8119ca1e0556a9a09685e28e821649aebbc62ab910db30060b2f13592a6f54de234aeea068d8b807fea9d6d1da29a
7
- data.tar.gz: bf4dee90d7003d74af59a34620456c00213e51d11b9d0317468adc706bae4ed3957c0291643fcbdc87c26bb9cf867a05b5f467ecff1935ab63c1e9cda1cb0fac
6
+ metadata.gz: 6ce8638946c47268506f2f3877097011afb924fe7c9a744dee23aa893afbfd3b2d683456bb3f3460c330ab005cd62e37d05cfbd94e9b5e80027cb9588466f9c4
7
+ data.tar.gz: 6669c9151391f60e52361d8ed3d680c7f6aca7ec5639256ce3717ac283daefad2b9f49e018cbd8322cf0fac2e964b889dc7e5d4690cf44036e93ba17adad55da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## LucaRecord 0.7.0
2
+
3
+ Reworked global constants to be singleton Class instance:
4
+
5
+ * Breaking change: LucaSupport::CONFIG is now LucaSupport::CONST.config
6
+ * Breaking change: LucaSupport::PJDIR is now LucaSupport::CONST.pjdir
7
+ * Removed bundler from test suite avoiding casual native build
8
+
1
9
  ## LucaRecord 0.5.6
2
10
 
3
11
  * add Nushell render mode: expand(default) | collapse | explore(`less` like)
data/lib/luca_cmd.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'luca_record'
3
+
4
+ class LucaCmd
5
+ def self.check_dir(target)
6
+ unless Dir.exist?('data')
7
+ 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?
10
+
11
+ Dir.chdir(d)
12
+ end
13
+ end
14
+ LucaRecord::Base.load_project(Dir.pwd)
15
+ LucaRecord::Base.valid_project?
16
+ yield
17
+ end
18
+ end
@@ -6,8 +6,6 @@ require 'luca_support'
6
6
 
7
7
  module LucaRecord
8
8
  class Base
9
- CONFIG = LucaSupport::CONFIG
10
- PJDIR = LucaSupport::PJDIR
11
9
  include LucaRecord::IO
12
10
  include LucaSupport::View
13
11
  end
@@ -126,7 +126,7 @@ module LucaRecord
126
126
  end
127
127
 
128
128
  def self.dict_path(filename)
129
- Pathname(LucaSupport::PJDIR) / 'dict' / filename
129
+ Pathname(CONST.pjdir) / 'dict' / filename
130
130
  end
131
131
 
132
132
  def self.reverse(dict)
@@ -8,7 +8,7 @@ require 'json'
8
8
  require 'yaml'
9
9
  require 'pathname'
10
10
  require 'luca_support/code'
11
- require 'luca_support/config'
11
+ require 'luca_support/const'
12
12
 
13
13
  module LucaRecord # :nodoc:
14
14
  # == IO
@@ -292,8 +292,20 @@ module LucaRecord # :nodoc:
292
292
  end
293
293
  end
294
294
 
295
+ def load_project(path)
296
+ CONST.set_pjdir(path)
297
+ begin
298
+ config = {
299
+ 'decimal_separator' => '.',
300
+ 'thousands_separator' => ','
301
+ }.merge(YAML.safe_load(File.read(Pathname(CONST.pjdir) / 'config.yml'), permitted_classes: [Date]))
302
+ end
303
+ config['decimal_num'] ||= config['country'] == 'jp' ? 0 : 2
304
+ CONST.set_config(config)
305
+ end
306
+
295
307
  # test if having required dirs/files under exec path
296
- def valid_project?(path = LucaSupport::PJDIR)
308
+ def valid_project?(path = CONST.pjdir)
297
309
  project_dir = Pathname(path)
298
310
  FileTest.file?((project_dir + 'config.yml').to_s) and FileTest.directory?( (project_dir + 'data').to_s)
299
311
  end
@@ -452,7 +464,7 @@ module LucaRecord # :nodoc:
452
464
 
453
465
  # TODO: replace with data_dir method
454
466
  def abs_path(base_dir)
455
- Pathname(LucaSupport::PJDIR) / 'data' / base_dir
467
+ Pathname(CONST.pjdir) / 'data' / base_dir
456
468
  end
457
469
 
458
470
  # True when file doesn't have record on code.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucaRecord
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/luca_record.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'luca_support'
4
- require 'luca_support/config'
3
+ require 'luca_support/const'
5
4
  require 'luca_record/version'
6
5
 
7
6
  module LucaRecord
7
+ CONST = LucaSupport::CONST
8
+
8
9
  autoload :Base, 'luca_record/base'
9
10
  autoload :Dict, 'luca_record/dict'
10
11
  end
@@ -3,7 +3,7 @@
3
3
  require 'date'
4
4
  require 'securerandom'
5
5
  require 'digest/sha1'
6
- require 'luca_support/config'
6
+ require 'luca_support/const'
7
7
 
8
8
  module LucaSupport # :nodoc:
9
9
  # implement Luca IDs convention
@@ -55,8 +55,8 @@ module LucaSupport # :nodoc:
55
55
  def delimit_num(num, decimal: nil, delimiter: nil)
56
56
  return nil if num.nil?
57
57
 
58
- decimal ||= LucaSupport::CONFIG['decimal_num']
59
- delimiter ||= LucaSupport::CONFIG['thousands_separator']
58
+ decimal ||= CONST.config['decimal_num']
59
+ delimiter ||= CONST.config['thousands_separator']
60
60
  case num
61
61
  when BigDecimal
62
62
  if decimal == 0
@@ -67,7 +67,7 @@ module LucaSupport # :nodoc:
67
67
  fragments[0].reverse!.gsub!(/(\d{3})(?=\d)/, '\1 ')
68
68
  fragments[0].reverse!.gsub!(/\s/, delimiter)
69
69
  fragments[1].gsub!(/(\d{3})(?=\d)/, '\1 ')
70
- fragments.join(LucaSupport::CONFIG['decimal_separator'])
70
+ fragments.join(CONST.config['decimal_separator'])
71
71
  end
72
72
  else
73
73
  num.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1 ').reverse!
@@ -162,7 +162,7 @@ module LucaSupport # :nodoc:
162
162
  end
163
163
  end
164
164
 
165
- def readable(obj, len = LucaSupport::CONFIG['decimal_num'])
165
+ def readable(obj, len = CONST.config['decimal_num'])
166
166
  case obj
167
167
  when Array
168
168
  obj.map { |i| readable(i) }
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ module LucaSupport
6
+ class ConstantHolder
7
+ include Singleton
8
+ attr_reader :config, :pjdir
9
+
10
+ def initialize
11
+ @pjdir = ENV['LUCA_TEST_DIR']
12
+ @config = {
13
+ 'decimal_separator' => '.',
14
+ 'decimal_num' => 2,
15
+ 'thousands_separator' => ','
16
+ }
17
+ end
18
+
19
+ def set_pjdir(path)
20
+ @pjdir ||= path
21
+ end
22
+
23
+ def set_config(config)
24
+ @config = config
25
+ end
26
+ end
27
+
28
+ CONST = ConstantHolder.instance
29
+ end
@@ -13,7 +13,7 @@ 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
- Dir.chdir(Pathname(PJDIR) / 'data') do
16
+ Dir.chdir(Pathname(CONST.pjdir) / 'data') do
17
17
  system "tar -czf - #{dir} | openssl enc -e -aes256 -iter #{iter} -out #{dir}.tar.gz"
18
18
  return if ! cleanup
19
19
 
@@ -23,7 +23,7 @@ module LucaSupport # :nodoc:
23
23
 
24
24
  # TODO: check space in dir string
25
25
  def decrypt(dir, iter: 10000)
26
- Dir.chdir(Pathname(PJDIR) / 'data') do
26
+ Dir.chdir(Pathname(CONST.pjdir) / 'data') do
27
27
  system "openssl enc -d -aes256 -iter #{iter} -in #{dir}.tar.gz | tar xz"
28
28
  end
29
29
  end
@@ -41,7 +41,7 @@ module LucaSupport
41
41
  #
42
42
  def search_template(file, dir = 'templates')
43
43
  # TODO: load config
44
- [LucaSupport::PJDIR, lib_path].each do |base|
44
+ [CONST.pjdir, lib_path].each do |base|
45
45
  path = (Pathname(base) / dir / file)
46
46
  return path.to_path if path.file?
47
47
  end
data/lib/luca_support.rb CHANGED
@@ -3,8 +3,6 @@
3
3
  module LucaSupport
4
4
  autoload :Code, 'luca_support/code'
5
5
  autoload :Enc, 'luca_support/enc'
6
- autoload :CONFIG, 'luca_support/config'
7
- autoload :Config, 'luca_support/config'
8
6
  autoload :Mail, 'luca_support/mail'
9
7
  autoload :View, 'luca_support/view'
10
8
  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.6.0
4
+ version: 0.7.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: 2023-04-20 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,6 +63,7 @@ extra_rdoc_files: []
63
63
  files:
64
64
  - CHANGELOG.md
65
65
  - LICENSE
66
+ - lib/luca_cmd.rb
66
67
  - lib/luca_record.rb
67
68
  - lib/luca_record/base.rb
68
69
  - lib/luca_record/dict.rb
@@ -70,7 +71,7 @@ files:
70
71
  - lib/luca_record/version.rb
71
72
  - lib/luca_support.rb
72
73
  - lib/luca_support/code.rb
73
- - lib/luca_support/config.rb
74
+ - lib/luca_support/const.rb
74
75
  - lib/luca_support/enc.rb
75
76
  - lib/luca_support/mail.rb
76
77
  - lib/luca_support/range.rb
@@ -82,7 +83,7 @@ metadata:
82
83
  homepage_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
83
84
  source_code_uri: https://github.com/chumaltd/luca/tree/master/lucarecord
84
85
  changelog_uri: https://github.com/chumaltd/luca/tree/master/lucarecord/CHANGELOG.md
85
- post_install_message:
86
+ post_install_message:
86
87
  rdoc_options: []
87
88
  require_paths:
88
89
  - lib
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  requirements: []
100
101
  rubygems_version: 3.4.10
101
- signing_key:
102
+ signing_key:
102
103
  specification_version: 4
103
104
  summary: ERP File operation framework
104
105
  test_files: []
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'date'
4
- require 'pathname'
5
- require 'yaml'
6
-
7
- # startup config
8
- #
9
- module LucaSupport
10
- PJDIR = ENV['LUCA_TEST_DIR'] || Dir.pwd.freeze
11
- CONFIG = begin
12
- {
13
- 'decimal_separator' => '.',
14
- 'thousands_separator' => ','
15
- }.merge(YAML.safe_load(File.read(Pathname(PJDIR) / 'config.yml'), permitted_classes: [Date]))
16
- rescue Errno::ENOENT
17
- {
18
- 'decimal_separator' => '.',
19
- 'thousands_separator' => ','
20
- }
21
- end
22
- CONFIG['decimal_num'] ||= CONFIG['country'] == 'jp' ? 0 : 2
23
- end