Class: ActiveRecord::Tenanted::UntenantedConnectionPool
- Inherits:
-
ConnectionAdapters::NullPool
- Object
- ConnectionAdapters::NullPool
- ActiveRecord::Tenanted::UntenantedConnectionPool
- Defined in:
- lib/active_record/tenanted/untenanted_connection_pool.rb
Overview
In an untenanted context, instances of this class are returned by ‘Tenant.connection_pool`.
Many places in Rails assume that ‘.connection_pool` can be called and will return an object, and so we can’t just raise an exception if it’s called while untenanted.
Instead, this class exists to provide a minimal set of features that don’t need a database connection, and that will raise if a connection is attempted.
Instance Attribute Summary collapse
-
#db_config ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #checkout ⇒ Object
-
#initialize(db_config, model) ⇒ UntenantedConnectionPool
constructor
A new instance of UntenantedConnectionPool.
- #lease_connection ⇒ Object
- #new_connection ⇒ Object
- #schema_cache ⇒ Object
- #schema_reflection ⇒ Object
- #size ⇒ Object
- #with_connection ⇒ Object
Constructor Details
#initialize(db_config, model) ⇒ UntenantedConnectionPool
Returns a new instance of UntenantedConnectionPool.
15 16 17 18 19 20 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 15 def initialize(db_config, model) super() @db_config = db_config @model = model end |
Instance Attribute Details
#db_config ⇒ Object (readonly)
:nodoc:
13 14 15 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 13 def db_config @db_config end |
Instance Method Details
#checkout ⇒ Object
39 40 41 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 39 def checkout(...) raise Tenanted::NoTenantError, "Cannot connect to a tenanted database while untenanted (#{@model})." end |
#lease_connection ⇒ Object
35 36 37 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 35 def lease_connection(...) raise Tenanted::NoTenantError, "Cannot connect to a tenanted database while untenanted (#{@model})." end |
#new_connection ⇒ Object
47 48 49 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 47 def new_connection(...) raise Tenanted::NoTenantError, "Cannot connect to a tenanted database while untenanted (#{@model})." end |
#schema_cache ⇒ Object
27 28 29 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 27 def schema_cache ActiveRecord::ConnectionAdapters::BoundSchemaReflection.new(schema_reflection, self) end |
#schema_reflection ⇒ Object
22 23 24 25 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 22 def schema_reflection schema_cache_path = ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename(db_config) ActiveRecord::ConnectionAdapters::SchemaReflection.new(schema_cache_path) end |
#size ⇒ Object
31 32 33 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 31 def size db_config.max_connections end |
#with_connection ⇒ Object
43 44 45 |
# File 'lib/active_record/tenanted/untenanted_connection_pool.rb', line 43 def with_connection(...) raise Tenanted::NoTenantError, "Cannot connect to a tenanted database while untenanted (#{@model})." end |