Active Record 資料庫 URL 設定
會為建立自 URL 的每個資料庫設定項目建立一個 UrlConfig
物件。這可以是 URL 字串或雜湊,雜湊內放有設定雜湊的 URL。
一個 URL 設定
postgres://localhost/foo
變成
#<ActiveRecord::DatabaseConfigurations::UrlConfig:0x00007fdc3238f340
@env_name="default_env", @name="primary",
@config={adapter: "postgresql", database: "foo", host: "localhost"},
@url="postgres://localhost/foo">
參閱 ActiveRecord::DatabaseConfigurations
以取得更多資訊。
方法
- N
屬性
[R] | url |
類別公開方法
new(env_name, name, url, configuration_hash = {}) 連結
初始化新的 UrlConfig
物件
選項
-
:env_name
- Rails 環境,例如「開發」。 -
:name
- 資料庫設定名稱。在標準的雙層資料庫設定中,這預設為「primary」。在多個資料庫的三層資料庫設定中,這相當於第二層使用的名稱,例如「primary_readonly」。 -
:url
- 資料庫 URL。 -
:config
- 設定雜湊。這是一個包含資料庫介面程式、名稱和其他重要資料庫連線資訊的雜湊。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/database_configurations/url_config.rb, line 40 def initialize(env_name, name, url, configuration_hash = {}) super(env_name, name, configuration_hash) @url = url @configuration_hash = @configuration_hash.merge(build_url_hash) if @configuration_hash[:schema_dump] == "false" @configuration_hash[:schema_dump] = false end if @configuration_hash[:query_cache] == "false" @configuration_hash[:query_cache] = false end to_boolean!(@configuration_hash, :replica) to_boolean!(@configuration_hash, :database_tasks) @configuration_hash.freeze end