Class: ActiveRecord::Tenanted::DatabaseConfigurations::TenantConfig
- Inherits:
-
DatabaseConfigurations::HashConfig
- Object
- DatabaseConfigurations::HashConfig
- ActiveRecord::Tenanted::DatabaseConfigurations::TenantConfig
- Defined in:
- lib/active_record/tenanted/database_configurations/tenant_config.rb
Instance Method Summary collapse
- #config_adapter ⇒ Object
- #default_schema_cache_path(db_dir = "db") ⇒ Object
-
#initialize ⇒ TenantConfig
constructor
A new instance of TenantConfig.
- #new_connection ⇒ Object
- #primary? ⇒ Boolean
- #schema_dump(format = ActiveRecord.schema_format) ⇒ Object
- #tenant ⇒ Object
- #tenanted_config_name ⇒ Object
Constructor Details
#initialize ⇒ TenantConfig
Returns a new instance of TenantConfig.
7 8 9 10 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 7 def initialize(...) super @config_adapter = nil end |
Instance Method Details
#config_adapter ⇒ Object
16 17 18 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 16 def config_adapter @config_adapter ||= ActiveRecord::Tenanted::DatabaseAdapter.new(self) end |
#default_schema_cache_path(db_dir = "db") ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 44 def default_schema_cache_path(db_dir = "db") if primary? super else File.join(db_dir, "#{tenanted_config_name}_schema_cache.yml") end end |
#new_connection ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 20 def new_connection # TODO: This line can be removed once rails/rails@f1f60dc1 is in a released version of # Rails, and this gem's dependency has been bumped to require that version or later. config_adapter.ensure_database_directory_exists super.tap { |connection| connection.tenant = tenant } end |
#primary? ⇒ Boolean
32 33 34 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 32 def primary? ActiveRecord::Base.configurations.primary?(tenanted_config_name) end |
#schema_dump(format = ActiveRecord.schema_format) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 36 def schema_dump(format = ActiveRecord.schema_format) if configuration_hash.key?(:schema_dump) || primary? super else "#{tenanted_config_name}_#{schema_file_type(format)}" end end |
#tenant ⇒ Object
12 13 14 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 12 def tenant configuration_hash.fetch(:tenant) end |
#tenanted_config_name ⇒ Object
28 29 30 |
# File 'lib/active_record/tenanted/database_configurations/tenant_config.rb', line 28 def tenanted_config_name configuration_hash.fetch(:tenanted_config_name) end |