Class: Ca::DataStore::Ar::DomainConfigRegistrar
- Inherits:
-
Object
- Object
- Ca::DataStore::Ar::DomainConfigRegistrar
- Includes:
- TR::CondUtils
- Defined in:
- lib/ca/data_store/ar/domain_config_registrar.rb
Constant Summary collapse
- CONFIG_FILE_NAME =
"cads_ar_domain_config.yml"
Class Method Summary collapse
Instance Method Summary collapse
- #domain_config_path(domain) ⇒ Object
-
#initialize(rec = { }) ⇒ DomainConfigRegistrar
constructor
A new instance of DomainConfigRegistrar.
- #is_domain_registered?(domain) ⇒ Boolean
- #logger ⇒ Object
- #register_domain(domain, path_to_config) ⇒ Object
- #registrar ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(rec = { }) ⇒ DomainConfigRegistrar
Returns a new instance of DomainConfigRegistrar.
46 47 48 49 50 51 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 46 def initialize(rec = { }) @reg = rec if is_empty?(@reg) @reg[:default] = "./config/database.yml" end end |
Class Method Details
.env_key ⇒ Object
42 43 44 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 42 def self.env_key "CADS_AR_DCR_PATH".freeze end |
.load_registrar ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 13 def self.load_registrar path = registrar_storage_path logger.debug "Load DCR from : #{path}" res = {} if File.exist?(path) File.open(path, "r") do |f| res = YAML.load(f.read) end end DomainConfigRegistrar.new(res) end |
.logger ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 34 def self.logger if @logger.nil? @logger = TeLogger::Tlogger.new @logger.tag = :DCR end @logger end |
.registrar_storage_path ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 26 def self.registrar_storage_path # allow caller to overwrite where to store via the env variable # CADS_AR_DCR_PATH val = ENV[env_key] || File.join(Dir.home,".cads_ar") FileUtils.mkdir_p(val) if not File.exist?(val) File.join(val, CONFIG_FILE_NAME) end |
Instance Method Details
#domain_config_path(domain) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 65 def domain_config_path(domain) v = registrar[domain] if is_empty?(v) "./config/database.yml" else v end end |
#is_domain_registered?(domain) ⇒ Boolean
61 62 63 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 61 def is_domain_registered?(domain) registrar.keys.include?(domain) end |
#logger ⇒ Object
89 90 91 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 89 def logger self.class.logger end |
#register_domain(domain, path_to_config) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 53 def register_domain(domain, path_to_config) raise Error, "Domain cannot be empty" if is_empty?(domain) raise Error, "Path-to-config cannot be empty" if is_empty?(path_to_config) # path-to-config is expected to be the typical database.yml registrar[domain] = path_to_config end |
#registrar ⇒ Object
82 83 84 85 86 87 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 82 def registrar if @reg.nil? @reg = {} end @reg end |
#save ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/ca/data_store/ar/domain_config_registrar.rb', line 74 def save path = self.class.registrar_storage_path logger.debug "Store DCR to : #{path}" File.open(path,"w") do |f| f.write YAML.dump(registrar) end end |