Class: App::Database
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
-
#initialize ⇒ Database
constructor
Ищем секцию настроек Cfg.db.
Constructor Details
#initialize ⇒ Database
Ищем секцию настроек Cfg.db
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/app-database.rb', line 19 def initialize raise ArgumentError.new("Cfg not found!") if ! defined?( ::Cfg ) || ! Cfg.db || Cfg.db.empty? if (! defined? @db ) || ( @db.nil? ) || ( ! @db ) || ( ! @db.test_connection ) Log.info{ "БД #{ Cfg.db.database }." } Sequel.extension :pg_array, :pg_inet, :pg_json, :pg_json_ops, :pg_array, :pg_array_ops, :pg_row, :pg_hstore, :pg_json_ops Sequel::Model.raise_on_save_failure = false Sequel::Model.plugin :validation_helpers Sequel::Database.extension :pg_inet, :pg_json, :pg_array, :pg_range, :pg_row, :pg_enum counter = Cfg.app.tmout.database_start begin @db = Sequel.connect Cfg.db.to_hash rescue Sequel::DatabaseConnectionError => e Log.error{"Шо-то с базой: #{ ( e.message.dup ).force_encoding('UTF-8') }"} ( counter -= 1 ) > 0 ? ( sleep(1); retry ) : raise end Sequel::Model.db = @db @db.tables.each{ |t| @db.reset_primary_key_sequence t } # Настоящие герои всегда идут в обход @db.freeze if Cfg.env == :production Kernel.const_set 'Db', @db end return @db end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
15 16 17 |
# File 'lib/app-database.rb', line 15 def db @db end |