lib/tobox/configuration.rb in tobox-0.4.0 vs lib/tobox/configuration.rb in tobox-0.4.1

- old
+ new

@@ -61,11 +61,13 @@ @default_logger.level = @config[:log_level] || (env == "production" ? Logger::INFO : Logger::DEBUG) @database = if @config[:database_uri] database_opts = {} database_opts[:max_connections] = @config[:concurrency] if @config[:worker] == :thread - Sequel.connect(@config[:database_uri].to_s, database_opts) + db = Sequel.connect(@config[:database_uri].to_s, database_opts) + Array(@lifecycle_events[:database_connect]).each { |cb| cb.call(db) } + db else Sequel::DATABASES.first end raise Error, "no database found" unless @database @@ -111,9 +113,14 @@ self end def on_error_worker(&callback) (@lifecycle_events[:error_worker] ||= []) << callback + self + end + + def on_database_connect(&callback) + (@lifecycle_events[:database_connect] ||= []) << callback self end def message_to_arguments(&callback) @arguments_handler = callback