ca-data_store-ar 0.1.2 → 0.1.5

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: b5415c75a20de2e01bf9430ca552bda0d47b88b6ae7710cb8eafe297ab3f4502
4
- data.tar.gz: 675667a02f7c0e56a44da4ba5b4475c20cf918cbb51dfa9f2b5621c1d1b5bbc2
3
+ metadata.gz: 96b72413fe17fd59be9e12cbbfc78bc60ba6c045d3a64a3e6b49473241299369
4
+ data.tar.gz: 34162704c41248c6229e0dcf633dd4a9be1d81f3b85c5e877f891e4c0b77f09e
5
5
  SHA512:
6
- metadata.gz: 6c570a7ef638ad54d7a861318702f23f60d5d2feaa940f9a95fcc77f3809e037e518605a7c9e8bd03e14adc077e0512d5f2529375c7a8d89171871a8f5d3c3ef
7
- data.tar.gz: ca92d6164331ffed80afe3358f2d49e338690094e920a2a9bce0f47795c312db64d1bb9c40b18a154986c03652f0cf5f3126527cb298ea69193f59b4538561dc
6
+ metadata.gz: 52eba9ca7040ab4914c428533ae624687b9f8b30242b78e4eea07b761c21e2b275e14a519f747fa40ed95c166a9c984393aa523c5c316180ce01afec1a2cc65f
7
+ data.tar.gz: 9556b9ca0cc92954118ca79dfb1e19145553789370752cd95507b7d9346ab4dc025517c595176384d4a7a14e723a53c24426a4f5515f016e632001a4b5de37e3
data/.release_history.yml CHANGED
@@ -4,3 +4,9 @@ ca-data_store-ar:
4
4
  :timestamp: 1664513882.3107193
5
5
  - :version: 0.1.1
6
6
  :timestamp: 1664551040.4916718
7
+ - :version: 0.1.2
8
+ :timestamp: 1668260793.5370069
9
+ - :version: 0.1.3
10
+ :timestamp: 1668267700.4040802
11
+ - :version: 0.1.4
12
+ :timestamp: 1668428550.0305433
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ca-data_store-ar (0.1.2)
4
+ ca-data_store-ar (0.1.4)
5
5
  activerecord
6
6
  activesupport
7
7
  ca-data_store
@@ -38,12 +38,12 @@ GEM
38
38
  tzinfo (~> 2.0)
39
39
  base58 (0.2.3)
40
40
  builder (3.2.4)
41
- ca-data_store (0.1.0)
41
+ ca-data_store (0.1.1)
42
42
  teLogger
43
43
  toolrack
44
44
  concurrent-ruby (1.1.10)
45
45
  crass (1.0.6)
46
- devops_assist (0.3.0)
46
+ devops_assist (0.3.1)
47
47
  git_cli
48
48
  git_cli_prompt
49
49
  gvcs
@@ -91,30 +91,28 @@ GEM
91
91
  thor (~> 1.0)
92
92
  zeitwerk (~> 2.5)
93
93
  rake (13.0.6)
94
- rspec (3.11.0)
95
- rspec-core (~> 3.11.0)
96
- rspec-expectations (~> 3.11.0)
97
- rspec-mocks (~> 3.11.0)
98
- rspec-core (3.11.0)
99
- rspec-support (~> 3.11.0)
100
- rspec-expectations (3.11.0)
94
+ rspec (3.12.0)
95
+ rspec-core (~> 3.12.0)
96
+ rspec-expectations (~> 3.12.0)
97
+ rspec-mocks (~> 3.12.0)
98
+ rspec-core (3.12.0)
99
+ rspec-support (~> 3.12.0)
100
+ rspec-expectations (3.12.0)
101
101
  diff-lcs (>= 1.2.0, < 2.0)
102
- rspec-support (~> 3.11.0)
103
- rspec-mocks (3.11.1)
102
+ rspec-support (~> 3.12.0)
103
+ rspec-mocks (3.12.0)
104
104
  diff-lcs (>= 1.2.0, < 2.0)
105
- rspec-support (~> 3.11.0)
106
- rspec-support (3.11.0)
107
- sqlite3 (1.4.4)
105
+ rspec-support (~> 3.12.0)
106
+ rspec-support (3.12.0)
107
+ sqlite3 (1.5.3-x86_64-linux)
108
108
  standalone_migrations (7.1.0)
109
109
  activerecord (>= 4.2.7, < 7.1.0, != 5.2.3.rc1, != 5.2.3)
110
110
  railties (>= 4.2.7, < 7.1.0, != 5.2.3.rc1, != 5.2.3)
111
111
  rake (>= 10.0)
112
112
  teLogger (0.2.0)
113
113
  thor (1.2.1)
114
- tlogger (0.26.3)
115
- toolrack (0.18.6)
114
+ toolrack (0.19.1)
116
115
  base58
117
- tlogger
118
116
  tty-color (0.6.0)
119
117
  tty-cursor (0.7.1)
120
118
  tty-prompt (0.23.1)
@@ -8,11 +8,16 @@ module Ca
8
8
  class DomainConfigRegistrar
9
9
  include TR::CondUtils
10
10
 
11
+ include TeLogger::TeLogHelper
12
+ teLogger_tag :DomConfReg
13
+
11
14
  CONFIG_FILE_NAME = "cads_ar_domain_config.yml"
15
+ CONFIG_FOLDER = ".cads_ar"
16
+ ENV_KEY = "CADS_AR_DCR_PATH".freeze
12
17
 
13
18
  def self.load_registrar
14
19
  path = registrar_storage_path
15
- logger.debug "Load DCR from : #{path}"
20
+ teLogger.debug "Load DCR from : #{path}"
16
21
  res = {}
17
22
  if File.exist?(path)
18
23
  File.open(path, "r") do |f|
@@ -26,21 +31,12 @@ module Ca
26
31
  def self.registrar_storage_path
27
32
  # allow caller to overwrite where to store via the env variable
28
33
  # CADS_AR_DCR_PATH
29
- val = ENV[env_key] || File.join(Dir.home,".cads_ar")
30
- FileUtils.mkdir_p(val) if not File.exist?(val)
31
- File.join(val, CONFIG_FILE_NAME)
32
- end
33
-
34
- def self.logger
35
- if @logger.nil?
36
- @logger = TeLogger::Tlogger.new
37
- @logger.tag = :DCR
34
+ if @storePath.nil?
35
+ val = ENV.fetch(ENV_KEY) { File.join(Dir.home, CONFIG_FOLDER) }
36
+ FileUtils.mkdir_p(val) if not File.exist?(val)
37
+ @storePath = File.join(val, CONFIG_FILE_NAME)
38
38
  end
39
- @logger
40
- end
41
-
42
- def self.env_key
43
- "CADS_AR_DCR_PATH".freeze
39
+ @storePath
44
40
  end
45
41
 
46
42
  def initialize(rec = { })
@@ -51,11 +47,14 @@ module Ca
51
47
  end
52
48
 
53
49
  def register_domain(domain, path_to_config)
54
- raise Error, "Domain cannot be empty" if is_empty?(domain)
55
- raise Error, "Path-to-config cannot be empty" if is_empty?(path_to_config)
50
+ if not_empty?(domain) and not_empty?(path_to_config)
51
+ # path-to-config is expected to be the typical database.yml
52
+ registrar[domain] = path_to_config
53
+ end
54
+ end
56
55
 
57
- # path-to-config is expected to be the typical database.yml
58
- registrar[domain] = path_to_config
56
+ def deregister_domain(domain)
57
+ registrar.delete(domain) if not_empty?(domain)
59
58
  end
60
59
 
61
60
  def is_domain_registered?(domain)
@@ -63,17 +62,12 @@ module Ca
63
62
  end
64
63
 
65
64
  def domain_config_path(domain)
66
- v = registrar[domain]
67
- if is_empty?(v)
68
- "./config/database.yml"
69
- else
70
- v
71
- end
65
+ registrar.fetch(domain) { "./config/database.yml" }
72
66
  end
73
67
 
74
68
  def save
75
69
  path = self.class.registrar_storage_path
76
- logger.debug "Store DCR to : #{path}"
70
+ teLogger.debug "Store DCR to : #{path}"
77
71
  File.open(path,"w") do |f|
78
72
  f.write YAML.dump(registrar)
79
73
  end
@@ -86,10 +80,6 @@ module Ca
86
80
  @reg
87
81
  end
88
82
 
89
- def logger
90
- self.class.logger
91
- end
92
-
93
83
  end # DomainConfigRegistrar
94
84
 
95
85
  end
@@ -10,7 +10,13 @@ module Ca
10
10
  # which in Ruby is totally up to developer
11
11
  #
12
12
  class Model < ActiveRecord::Base
13
- primary_abstract_class
13
+ #p defined?(Rails)
14
+ # remark this will tame rails in production mode
15
+ # BUT error when accessing model derive from here
16
+ # Leaving it here is ok in dev mode
17
+ #if not defined?(Rails)
18
+ primary_abstract_class
19
+ #end
14
20
  end
15
21
 
16
22
  end
@@ -3,7 +3,7 @@
3
3
  module Ca
4
4
  module DataStore
5
5
  module Ar
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.5"
7
7
  end
8
8
  end
9
9
  end
@@ -48,7 +48,14 @@ module Ca
48
48
  end
49
49
 
50
50
  def Ar.register_domain(domain, path, &block)
51
- domain_config.register_domain(domain, path)
51
+ if not is_domain_registered?(domain)
52
+ domain_config.register_domain(domain, path)
53
+ domain_config.save
54
+ end
55
+ end
56
+
57
+ def Ar.update_registered_domain(domain, path, &block)
58
+ domain_config.register_domain(domain, path)
52
59
  domain_config.save
53
60
  end
54
61
 
@@ -72,14 +79,22 @@ module Ca
72
79
  File.open(dbConfig,"r") do |f|
73
80
  @conf = YAML.load(f.read)
74
81
  end
75
-
76
- if block
77
- env = block.call(:env)
78
- end
79
- env = "development" if is_empty?(env)
80
82
 
81
- teLogger.debug "db env : #{env} / #{@conf[env.to_s]}"
82
- ActiveRecord::Base.establish_connection(@conf[env.to_s])
83
+ if @conf.is_a?(Hash)
84
+
85
+ if block
86
+ env = block.call(:env)
87
+ end
88
+ env = "development" if is_empty?(env)
89
+
90
+ # this assumed the content of the config file is like Rails style
91
+ teLogger.debug "db env : #{env} / #{@conf[env.to_s]}"
92
+ ActiveRecord::Base.establish_connection(@conf[env.to_s])
93
+
94
+ else
95
+ teLogger.debug "Config: #{@conf}"
96
+ ActiveRecord::Base.establish_connection(@conf)
97
+ end
83
98
 
84
99
  else
85
100
  teLogger.warn "Skipped ActiveRecord connection since config file not available at '#{path}'"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ca-data_store-ar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-12 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: teLogger