Module: Motel::Manager
- Defined in:
- lib/motel/manager.rb
Class Method Summary collapse
- .active_tenants ⇒ Object
- .add_tenant(name, spec) ⇒ Object
- .current_tenant ⇒ Object
- .delete_tenant(name) ⇒ Object
- .switch_tenant(name) ⇒ Object
- .tenant(name) ⇒ Object
- .tenant?(name) ⇒ Boolean
- .tenants ⇒ Object
- .tenants_source ⇒ Object
- .tenants_source_configurations(config) ⇒ Object
- .update_tenant(name, spec) ⇒ Object
Class Method Details
.active_tenants ⇒ Object
54 55 56 |
# File 'lib/motel/manager.rb', line 54 def active_tenants ::ActiveRecord::Base.connection_handler.active_tenants end |
.add_tenant(name, spec) ⇒ Object
33 34 35 36 |
# File 'lib/motel/manager.rb', line 33 def add_tenant(name, spec) tenants_source.add_tenant(name, spec) tenant?(name) end |
.current_tenant ⇒ Object
58 59 60 61 62 |
# File 'lib/motel/manager.rb', line 58 def current_tenant ENV['TENANT'] || Thread.current.thread_variable_get(:@current_tenant) || default_tenant end |
.delete_tenant(name) ⇒ Object
44 45 46 47 48 |
# File 'lib/motel/manager.rb', line 44 def delete_tenant(name) ::ActiveRecord::Base.remove_connection(name) tenants_source.delete_tenant(name) !tenant?(name) end |
.switch_tenant(name) ⇒ Object
50 51 52 |
# File 'lib/motel/manager.rb', line 50 def switch_tenant(name) Thread.current.thread_variable_set(:@current_tenant, name) end |
.tenant(name) ⇒ Object
25 26 27 |
# File 'lib/motel/manager.rb', line 25 def tenant(name) tenants_source.tenant(name) end |
.tenant?(name) ⇒ Boolean
29 30 31 |
# File 'lib/motel/manager.rb', line 29 def tenant?(name) tenants_source.tenant?(name) end |
.tenants ⇒ Object
21 22 23 |
# File 'lib/motel/manager.rb', line 21 def tenants tenants_source.tenants end |
.tenants_source ⇒ Object
64 65 66 |
# File 'lib/motel/manager.rb', line 64 def tenants_source ::ActiveRecord::Base.connection_handler.tenants_source end |
.tenants_source_configurations(config) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/motel/manager.rb', line 12 def tenants_source_configurations(config) source_type = config[:source] || 'default' source_class = "Motel::Sources::#{source_type.to_s.camelize}".constantize source_instance = source_class.new(config) ::ActiveRecord::Base.connection_handler.tenants_source = source_instance end |
.update_tenant(name, spec) ⇒ Object
38 39 40 41 42 |
# File 'lib/motel/manager.rb', line 38 def update_tenant(name, spec) ::ActiveRecord::Base.remove_connection(name) tenants_source.update_tenant(name, spec) tenant(name) end |