Module: Ca::DataStore::Ar
- Includes:
- TR::CondUtils, TeLogger::TeLogHelper
- Defined in:
- lib/ca/data_store/ar.rb,
lib/ca/data_store/ar/version.rb,
lib/ca/data_store/ar/provider.rb,
lib/ca/data_store/ar/model_base.rb,
lib/ca/data_store/ar/console_helper.rb,
lib/ca/data_store/ar/domain_config_registrar.rb,
lib/ca/data_store/ar/migration/migration_helper.rb
Defined Under Namespace
Modules: ConsoleHelper, MigrationHelper
Classes: DomainConfigRegistrar, Error, MigrateError, Model, Provider
Constant Summary
collapse
- VERSION =
"0.1.5"
Class Method Summary
collapse
Class Method Details
.connectdb(domain = :default, &block) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/ca/data_store/ar.rb', line 70
def Ar.connectdb(domain = :default, &block)
raise Ar::Error, "Domain must be given" if is_empty?(domain)
dbConfig = domain_config.domain_config_path(domain)
dbConfig = File.expand_path(dbConfig) if not_empty?(dbConfig)
teLogger.debug "dbConfig at : '#{dbConfig}'"
if File.exist?(dbConfig)
File.open(dbConfig,"r") do |f|
@conf = YAML.load(f.read)
end
if @conf.is_a?(Hash)
if block
env = block.call(:env)
end
env = "development" if is_empty?(env)
teLogger.debug "db env : #{env} / #{@conf[env.to_s]}"
ActiveRecord::Base.establish_connection(@conf[env.to_s])
else
teLogger.debug "Config: #{@conf}"
ActiveRecord::Base.establish_connection(@conf)
end
else
teLogger.warn "Skipped ActiveRecord connection since config file not available at '#{path}'"
end
end
|
.disconnectdb ⇒ Object
105
106
107
108
|
# File 'lib/ca/data_store/ar.rb', line 105
def Ar.disconnectdb
ActiveRecord::Base.remove_connection
end
|
.domain_config_path(domain) ⇒ Object
66
67
68
|
# File 'lib/ca/data_store/ar.rb', line 66
def Ar.domain_config_path(domain)
domain_config.domain_config_path(domain)
end
|
.is_domain_registered?(domain) ⇒ Boolean
62
63
64
|
# File 'lib/ca/data_store/ar.rb', line 62
def Ar.is_domain_registered?(domain)
domain_config.is_domain_registered?(domain)
end
|
.load_model(path) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/ca/data_store/ar.rb', line 43
def Ar.load_model(path)
mpath = File.expand_path(path)
Dir.glob(File.join(mpath,"*.rb")) do |m|
require m
end
end
|
.load_tasks ⇒ Object
36
37
38
39
40
41
|
# File 'lib/ca/data_store/ar.rb', line 36
def Ar.load_tasks
Dir.glob(File.join(File.dirname(__FILE__),"..","..","..","tasks","*.rake")) do |rf|
fp = File.expand_path(rf)
load fp
end
end
|
.register_domain(domain, path, &block) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/ca/data_store/ar.rb', line 50
def Ar.register_domain(domain, path, &block)
if not is_domain_registered?(domain)
domain_config.register_domain(domain, path)
domain_config.save
end
end
|
.show_log(out = nil) ⇒ Object
110
111
112
|
# File 'lib/ca/data_store/ar.rb', line 110
def Ar.show_log(out = nil)
ActiveRecord::Base.logger = TeLogger::Tlogger.new(out)
end
|
.update_registered_domain(domain, path, &block) ⇒ Object
57
58
59
60
|
# File 'lib/ca/data_store/ar.rb', line 57
def Ar.update_registered_domain(domain, path, &block)
domain_config.register_domain(domain, path)
domain_config.save
end
|