active_tenant 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +1,41 @@
1
- module ActiveTenant
2
- class Base
3
- ADAPTERS = {
4
- sqlite3: SQLiteAdapter,
5
- postgresql: PostgresAdapter
6
- }
7
-
8
- delegate :all, :create, :remove, :with, :name, :global, :global?, to: :adapter
9
-
10
- def migrate(name, version=nil)
11
- ::ActiveRecord::Base.logger.info "[ActiveTenant] Migrating tenant: #{name}"
12
- with name do
13
- ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
14
- [:all, ::ActiveRecord::Base.tenant_name.to_sym].include? migration_proxy.send(:migration).class.tenant
15
- end
16
- end
17
- end
18
-
19
- def migrate_all(version=nil)
20
- all.each do |tenant|
21
- migrate tenant, version
22
- end
23
- end
24
-
25
- def migrate_global(version=nil)
26
- ::ActiveRecord::Base.logger.info '[ActiveTenant] Migrating global db'
27
- with global do
28
- ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
29
- migration_proxy.send(:migration).class.tenant.nil?
30
- end
31
- end
32
- end
33
-
34
- private
35
-
36
- def adapter
37
- @adapter ||= ADAPTERS[::ActiveRecord::Base.connection_config[:adapter].to_sym].new
38
- end
39
-
40
- end
1
+ module ActiveTenant
2
+ class Base
3
+ ADAPTERS = {
4
+ sqlite3: SQLiteAdapter,
5
+ postgresql: PostgresAdapter
6
+ }
7
+
8
+ delegate :all, :create, :remove, :with, :connection_settings, :name, :global, :global?, to: :adapter
9
+
10
+ def migrate(name, version=nil)
11
+ ::ActiveRecord::Base.logger.info "[ActiveTenant] Migrating tenant: #{name}"
12
+ with name do
13
+ ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
14
+ [:all, ::ActiveRecord::Base.tenant_name.to_sym].include? migration_proxy.send(:migration).class.tenant
15
+ end
16
+ end
17
+ end
18
+
19
+ def migrate_all(version=nil)
20
+ all.each do |tenant|
21
+ migrate tenant, version
22
+ end
23
+ end
24
+
25
+ def migrate_global(version=nil)
26
+ ::ActiveRecord::Base.logger.info '[ActiveTenant] Migrating global db'
27
+ with global do
28
+ ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
29
+ migration_proxy.send(:migration).class.tenant.nil?
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def adapter
37
+ @adapter ||= ADAPTERS[::ActiveRecord::Base.connection_config[:adapter].to_sym].new
38
+ end
39
+
40
+ end
41
41
  end
@@ -1,5 +1,5 @@
1
- module ActiveTenant
2
- class Configuration
3
- attr_accessor :global
4
- end
1
+ module ActiveTenant
2
+ class Configuration
3
+ attr_accessor :global
4
+ end
5
5
  end
@@ -1,4 +1,4 @@
1
- module ActiveTenant
2
- class Engine < ::Rails::Engine
3
- end
1
+ module ActiveTenant
2
+ class Engine < ::Rails::Engine
3
+ end
4
4
  end
@@ -1,3 +1,3 @@
1
- module ActiveTenant
2
- VERSION = '0.0.2'
3
- end
1
+ module ActiveTenant
2
+ VERSION = '0.0.3'
3
+ end
data/lib/active_tenant.rb CHANGED
@@ -1,29 +1,29 @@
1
- require 'rails'
2
- require 'active_record'
3
-
4
- require 'active_tenant/version'
5
- require 'active_tenant/engine'
6
- require 'active_tenant/adapters/sqlite_adapter'
7
- require 'active_tenant/adapters/postgres_adapter'
8
- require 'active_tenant/base'
9
- require 'active_tenant/active_record_extensions'
10
- require 'active_tenant/configuration'
11
-
12
- module ActiveTenant
13
-
14
- def self.configuration
15
- @@configuration ||= Configuration.new
16
- end
17
-
18
- def self.configure
19
- yield(configuration)
20
- end
21
-
22
- def self.current
23
- ActiveTenant::Base.new
24
- end
25
-
26
- end
27
-
28
- ActiveRecord::Base.send :extend, ActiveTenant::ActiveRecord::Base
29
- ActiveRecord::Migration.send :extend, ActiveTenant::ActiveRecord::Migration
1
+ require 'rails'
2
+ require 'active_record'
3
+
4
+ require 'active_tenant/version'
5
+ require 'active_tenant/engine'
6
+ require 'active_tenant/adapters/sqlite_adapter'
7
+ require 'active_tenant/adapters/postgres_adapter'
8
+ require 'active_tenant/base'
9
+ require 'active_tenant/active_record_extensions'
10
+ require 'active_tenant/configuration'
11
+
12
+ module ActiveTenant
13
+
14
+ def self.configuration
15
+ @@configuration ||= Configuration.new
16
+ end
17
+
18
+ def self.configure
19
+ yield(configuration)
20
+ end
21
+
22
+ def self.current
23
+ ActiveTenant::Base.new
24
+ end
25
+
26
+ end
27
+
28
+ ActiveRecord::Base.send :extend, ActiveTenant::ActiveRecord::Base
29
+ ActiveRecord::Migration.send :extend, ActiveTenant::ActiveRecord::Migration
@@ -1,21 +1,21 @@
1
- namespace :db do
2
- namespace :migrate do
3
-
4
- desc 'Migrate global db and all tenants'
5
- task :all => :environment do
6
- ActiveTenant.current.migrate_global
7
- ActiveTenant.current.migrate_all
8
- end
9
-
10
- desc 'Migrate only global db'
11
- task :global => :environment do
12
- ActiveTenant.current.migrate_global
13
- end
14
-
15
- desc 'Migrate all tenants excluding global db'
16
- task :tenants => :environment do
17
- ActiveTenant.current.migrate_all
18
- end
19
-
20
- end
21
- end
1
+ namespace :db do
2
+ namespace :migrate do
3
+
4
+ desc 'Migrate global db and all tenants'
5
+ task :all => :environment do
6
+ ActiveTenant.current.migrate_global
7
+ ActiveTenant.current.migrate_all
8
+ end
9
+
10
+ desc 'Migrate only global db'
11
+ task :global => :environment do
12
+ ActiveTenant.current.migrate_global
13
+ end
14
+
15
+ desc 'Migrate all tenants excluding global db'
16
+ task :tenants => :environment do
17
+ ActiveTenant.current.migrate_all
18
+ end
19
+
20
+ end
21
+ end