Class: Toaster::Config
- Inherits:
-
Object
- Object
- Toaster::Config
- Defined in:
- lib/toaster/util/config.rb
Overview
Author: Waldemar Hummer ([email protected])
Class Attribute Summary collapse
-
.values ⇒ Object
Returns the value of attribute values.
Class Method Summary collapse
- .get(key, v = values) ⇒ Object
- .init_db_connection(config = nil) ⇒ Object
- .set(key, value, v = values) ⇒ Object
Class Attribute Details
.values ⇒ Object
Returns the value of attribute values.
18 19 20 |
# File 'lib/toaster/util/config.rb', line 18 def values @values end |
Class Method Details
.get(key, v = values) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/toaster/util/config.rb', line 34 def self.get(key, v=values) parts = key.split(".") last_key = parts.pop # remove last key from array parts.each do |p| if !v[p] v[p] = {} end v = v[p] end v[last_key] end |
.init_db_connection(config = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/toaster/util/config.rb', line 46 def self.init_db_connection(config=nil) if $db_connection_initialized return end require "toaster/util/util" if !config || !config["mysql"] config = { "db_type" => "mysql", 'mysql' => Config.get('db') } end if config["db_type"] == "mysql" && config["mysql"] require "active_record" ActiveRecord::Base.establish_connection( :adapter => 'mysql2', :host => "#{config["mysql"]["host"]}".empty? ? get("db.host") : config["mysql"]["host"], :database => "#{config["mysql"]["database"]}".empty? ? get("db.database") : config["mysql"]["database"], :username => "#{config["mysql"]["username"]}".empty? ? get("db.username") : config["mysql"]["username"], :password => "#{config["mysql"]["password"]}".empty? ? get("db.password") : config["mysql"]["password"], :pool => 50 # connection pool size limit (default is 5 which is not sufficient) ) $db_connection_initialized = true else puts "WARN: Incorrect database connection configuration" end end |
.set(key, value, v = values) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/toaster/util/config.rb', line 23 def self.set(key,value, v=values) parts = key.split(".") last_key = parts.pop # remove last key from array parts.each do |p| if !v[p] v[p] = {} end v = v[p] end v[last_key] = value end |