Flowdock
method

register_db_config_handler

Importance_2
v7.1.3.2 - Show latest stable - 0 notes - Class: DatabaseConfigurations
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2 (0)
  • What's this?
register_db_config_handler(&block) public

Allows an application to register a custom handler for database configuration objects. This is useful for creating a custom handler that responds to methods your application needs but Active Record doesn’t implement. For example if you are using Vitess, you may want your Vitess configurations to respond to `sharded?`. To implement this define the following in an initializer:

ActiveRecord::DatabaseConfigurations.register_db_config_handler do |env_name, name, url, config|
  next unless config.key?(:vitess)
  VitessConfig.new(env_name, name, config)
end

Note: applications must handle the condition in which custom config should be created in your handler registration otherwise all objects will use the custom handler.

Then define your VitessConfig to respond to the methods your application needs. It is recommended that you inherit from one of the existing database config classes to avoid having to reimplement all methods. Custom config handlers should only implement methods Active Record does not.

class VitessConfig < ActiveRecord::DatabaseConfigurations::UrlConfig
  def sharded?
    configuration_hash.fetch("sharded", false)
  end
end

For configs that have a :vitess key, a VitessConfig object will be created instead of a UrlConfig.

Show source
Register or log in to add new notes.