Class: Tzispa::Config::DbConfig
- Inherits:
-
Object
- Object
- Tzispa::Config::DbConfig
- Defined in:
- lib/tzispa/config/db_config.rb
Constant Summary collapse
- CONFIG_FILENAME =
'database'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #filename ⇒ Object
-
#initialize(env) ⇒ DbConfig
constructor
A new instance of DbConfig.
- #load! ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(env) ⇒ DbConfig
Returns a new instance of DbConfig.
13 14 15 16 |
# File 'lib/tzispa/config/db_config.rb', line 13 def initialize(env) @cftime = nil @env = env.to_sym end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/tzispa/config/db_config.rb', line 9 def config @config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/tzispa/config/db_config.rb', line 9 def env @env end |
Class Method Details
.add_repository(name, adapter, dbconn) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tzispa/config/db_config.rb', line 51 def add_repository(name, adapter, dbconn) hs = YAML.safe_load(File.open(filename)) hs.each do |_, v| v[name] = { 'adapter' => adapter, 'database' => dbconn, 'connection_validation' => 'No', 'local' => 'Yes' } end Yaml.save(hs, filename) end |
.create_default(path) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/tzispa/config/db_config.rb', line 42 def create_default(path) hcfg = {}.tap do |cfg| cfg['development'] = '' cfg['deployment'] = '' cfg['test'] = '' end Yaml.save(hcfg, File.join(path, filename)) end |
.filename ⇒ Object
38 39 40 |
# File 'lib/tzispa/config/db_config.rb', line 38 def filename @filename ||= "config/#{CONFIG_FILENAME}.yml" end |
Instance Method Details
#filename ⇒ Object
33 34 35 |
# File 'lib/tzispa/config/db_config.rb', line 33 def filename DbConfig.filename end |
#load! ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/tzispa/config/db_config.rb', line 23 def load! if @cftime.nil? @cftime = File.ctime(filename) elsif @cftime != File.ctime(filename) @config = nil @cftime = File.ctime(filename) end @config ||= Tzispa::Config::Yaml.load(filename) end |
#to_h ⇒ Object
18 19 20 21 |
# File 'lib/tzispa/config/db_config.rb', line 18 def to_h load! config.to_h[env]&.to_h end |