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.
- data/.gitignore +18 -18
- data/.travis.yml +5 -0
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/README.md +41 -39
- data/Rakefile +2 -2
- data/active_tenant.gemspec +23 -23
- data/lib/active_tenant/active_record_extensions.rb +59 -55
- data/lib/active_tenant/adapters/postgres_adapter.rb +72 -69
- data/lib/active_tenant/adapters/sqlite_adapter.rb +75 -71
- data/lib/active_tenant/base.rb +40 -40
- data/lib/active_tenant/configuration.rb +4 -4
- data/lib/active_tenant/engine.rb +3 -3
- data/lib/active_tenant/version.rb +3 -3
- data/lib/active_tenant.rb +29 -29
- data/lib/tasks/migration.rake +21 -21
- data/spec/adapters_spec.rb +249 -217
- data/spec/migrations/20120823132512_create_globals.rb +10 -10
- data/spec/migrations/20120823132854_create_tenants.rb +12 -12
- data/spec/migrations/20120823132856_create_other_tenants.rb +12 -12
- data/spec/migrations/20120823132902_create_customs.rb +12 -12
- data/spec/models.rb +12 -0
- data/spec/spec_helper.rb +8 -10
- data/spec/support/adapter_test_helper.rb +69 -58
- metadata +40 -11
data/.gitignore
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
.idea
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.idea
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in active_tenant.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in active_tenant.gemspec
|
4
|
+
gemspec
|
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2012 gabriel
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2012 gabriel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,39 +1,41 @@
|
|
1
|
-
# ActiveTenant
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
ActiveRecord::
|
24
|
-
|
25
|
-
ActiveRecord::Migration.
|
26
|
-
|
27
|
-
ActiveRecord::
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
1
|
+
# ActiveTenant
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/gabynaiman/active_tenant.png?branch=master)](https://travis-ci.org/gabynaiman/active_tenant)
|
4
|
+
|
5
|
+
ActiveRecord extensions for multi tenant applications
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'active_tenant'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install active_tenant
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
ActiveRecord::Base.create_tenant 'customer_name'
|
24
|
+
|
25
|
+
ActiveRecord::Migration.migrate_tenant 'customer_name'
|
26
|
+
# or
|
27
|
+
ActiveRecord::Migration.migrate_all_tenants
|
28
|
+
|
29
|
+
ActiveRecord::Base.with_tenant 'customer_name' do
|
30
|
+
Porduct.find(1234)
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.remove_tenant 'customer_name'
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require "bundler/gem_tasks"
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
data/active_tenant.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/active_tenant/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = 'active_tenant'
|
6
|
-
s.version = ActiveTenant::VERSION
|
7
|
-
s.authors = ['Gabriel Naiman']
|
8
|
-
s.email = ['gabynaiman@gmail.com']
|
9
|
-
s.description = 'ActiveRecord extensions for multi tenant applications'
|
10
|
-
s.summary = 'ActiveRecord extensions for multi tenant applications'
|
11
|
-
s.homepage = 'https://github.com/gabynaiman/active_tenant'
|
12
|
-
|
13
|
-
s.files = `git ls-files`.split($\)
|
14
|
-
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
|
18
|
-
s.add_dependency 'rails', '>= 3.2.0'
|
19
|
-
|
20
|
-
s.add_development_dependency 'pg'
|
21
|
-
s.add_development_dependency 'sqlite3'
|
22
|
-
s.add_development_dependency 'rspec'
|
23
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/active_tenant/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'active_tenant'
|
6
|
+
s.version = ActiveTenant::VERSION
|
7
|
+
s.authors = ['Gabriel Naiman']
|
8
|
+
s.email = ['gabynaiman@gmail.com']
|
9
|
+
s.description = 'ActiveRecord extensions for multi tenant applications'
|
10
|
+
s.summary = 'ActiveRecord extensions for multi tenant applications'
|
11
|
+
s.homepage = 'https://github.com/gabynaiman/active_tenant'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency 'rails', '>= 3.2.0'
|
19
|
+
|
20
|
+
s.add_development_dependency 'pg'
|
21
|
+
s.add_development_dependency 'sqlite3'
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
end
|
@@ -1,56 +1,60 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
module ActiveRecord
|
3
|
-
module Base
|
4
|
-
|
5
|
-
def all_tenants
|
6
|
-
ActiveTenant.current.all
|
7
|
-
end
|
8
|
-
|
9
|
-
def create_tenant(name)
|
10
|
-
ActiveTenant.current.create name
|
11
|
-
end
|
12
|
-
|
13
|
-
def remove_tenant(name)
|
14
|
-
ActiveTenant.current.remove name
|
15
|
-
end
|
16
|
-
|
17
|
-
def with_tenant(name)
|
18
|
-
ActiveTenant.current.with(name) { yield }
|
19
|
-
end
|
20
|
-
|
21
|
-
def tenant?
|
22
|
-
!ActiveTenant.current.global?
|
23
|
-
end
|
24
|
-
|
25
|
-
def tenant_name
|
26
|
-
ActiveTenant.current.name if tenant?
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def
|
42
|
-
ActiveTenant.current.
|
43
|
-
end
|
44
|
-
|
45
|
-
def
|
46
|
-
ActiveTenant.current.
|
47
|
-
end
|
48
|
-
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
module ActiveTenant
|
2
|
+
module ActiveRecord
|
3
|
+
module Base
|
4
|
+
|
5
|
+
def all_tenants
|
6
|
+
ActiveTenant.current.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_tenant(name)
|
10
|
+
ActiveTenant.current.create name
|
11
|
+
end
|
12
|
+
|
13
|
+
def remove_tenant(name)
|
14
|
+
ActiveTenant.current.remove name
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_tenant(name)
|
18
|
+
ActiveTenant.current.with(name) { yield }
|
19
|
+
end
|
20
|
+
|
21
|
+
def tenant?
|
22
|
+
!ActiveTenant.current.global?
|
23
|
+
end
|
24
|
+
|
25
|
+
def tenant_name
|
26
|
+
ActiveTenant.current.name if tenant?
|
27
|
+
end
|
28
|
+
|
29
|
+
def belongs_to_tenant_global
|
30
|
+
establish_connection ActiveTenant.current.connection_settings(ActiveTenant.current.global)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
module Migration
|
36
|
+
|
37
|
+
def tenant(name=nil)
|
38
|
+
name ? @tenant_name = name : @tenant_name
|
39
|
+
end
|
40
|
+
|
41
|
+
def migrate_global(version=nil)
|
42
|
+
ActiveTenant.current.migrate_global version
|
43
|
+
end
|
44
|
+
|
45
|
+
def migrate_tenant(name, version=nil)
|
46
|
+
ActiveTenant.current.migrate name, version
|
47
|
+
end
|
48
|
+
|
49
|
+
def migrate_all_tenants(version=nil)
|
50
|
+
ActiveTenant.current.migrate_all version
|
51
|
+
end
|
52
|
+
|
53
|
+
def migrate_all(version=nil)
|
54
|
+
migrate_global version
|
55
|
+
migrate_all_tenants version
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
56
60
|
end
|
@@ -1,70 +1,73 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
class PostgresAdapter
|
3
|
-
delegate :connection_config, :establish_connection, :connection, to: ::ActiveRecord::Base
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.global = ActiveTenant.configuration.global if ActiveTenant.configuration.global
|
7
|
-
end
|
8
|
-
|
9
|
-
def all
|
10
|
-
connection.select_values("SELECT nspname FROM pg_namespace WHERE nspname <> 'information_schema' AND nspname NOT LIKE 'pg%'") - [global]
|
11
|
-
end
|
12
|
-
|
13
|
-
def create(name)
|
14
|
-
unless all.include? name
|
15
|
-
connection.execute "CREATE SCHEMA \"#{name}\""
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def remove(name)
|
20
|
-
if all.include? name
|
21
|
-
connection.execute "DROP SCHEMA \"#{name}\" CASCADE"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def with(name)
|
26
|
-
return yield if name == search_path
|
27
|
-
|
28
|
-
ex = nil
|
29
|
-
current_schema = search_path
|
30
|
-
search_path name
|
31
|
-
begin
|
32
|
-
result = yield
|
33
|
-
rescue => e
|
34
|
-
ex = e
|
35
|
-
ensure
|
36
|
-
search_path current_schema
|
37
|
-
raise ex unless ex.nil?
|
38
|
-
result
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def name
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def global
|
51
|
-
global
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
1
|
+
module ActiveTenant
|
2
|
+
class PostgresAdapter
|
3
|
+
delegate :connection_config, :establish_connection, :connection, to: ::ActiveRecord::Base
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.global = ActiveTenant.configuration.global if ActiveTenant.configuration.global
|
7
|
+
end
|
8
|
+
|
9
|
+
def all
|
10
|
+
connection.select_values("SELECT nspname FROM pg_namespace WHERE nspname <> 'information_schema' AND nspname NOT LIKE 'pg%'") - [global]
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(name)
|
14
|
+
unless all.include? name
|
15
|
+
connection.execute "CREATE SCHEMA \"#{name}\""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove(name)
|
20
|
+
if all.include? name
|
21
|
+
connection.execute "DROP SCHEMA \"#{name}\" CASCADE"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def with(name)
|
26
|
+
return yield if name == search_path
|
27
|
+
|
28
|
+
ex = nil
|
29
|
+
current_schema = search_path
|
30
|
+
search_path name
|
31
|
+
begin
|
32
|
+
result = yield
|
33
|
+
rescue => e
|
34
|
+
ex = e
|
35
|
+
ensure
|
36
|
+
search_path current_schema
|
37
|
+
raise ex unless ex.nil?
|
38
|
+
result
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def connection_settings(name)
|
43
|
+
connection_config.merge(schema_search_path: name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def name
|
47
|
+
search_path
|
48
|
+
end
|
49
|
+
|
50
|
+
def global
|
51
|
+
@global || 'public'
|
52
|
+
end
|
53
|
+
|
54
|
+
def global?
|
55
|
+
global == name
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def global=(name)
|
61
|
+
@global = name
|
62
|
+
end
|
63
|
+
|
64
|
+
def search_path(name=nil)
|
65
|
+
if name
|
66
|
+
establish_connection connection_settings(name)
|
67
|
+
else
|
68
|
+
connection_config[:schema_search_path]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
70
73
|
end
|
@@ -1,72 +1,76 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
class SQLiteAdapter
|
3
|
-
delegate :connection_config, :establish_connection, :connection, to: ::ActiveRecord::Base
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.global = ActiveTenant.configuration.global if ActiveTenant.configuration.global
|
7
|
-
end
|
8
|
-
|
9
|
-
def all
|
10
|
-
path = database_path
|
11
|
-
Dir.glob("#{path}/*.sqlite3").map { |f| File.basename(f, '.sqlite3') } - [global]
|
12
|
-
end
|
13
|
-
|
14
|
-
def create(name)
|
15
|
-
unless all.include? name
|
16
|
-
current_config = connection_config
|
17
|
-
establish_connection current_config.merge(database: file_name(name))
|
18
|
-
connection
|
19
|
-
establish_connection current_config
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def remove(name)
|
24
|
-
file = file_name name
|
25
|
-
FileUtils.rm(file) if File.exist?(file)
|
26
|
-
end
|
27
|
-
|
28
|
-
def with(name)
|
29
|
-
return yield if name == self.name
|
30
|
-
|
31
|
-
current_config = connection_config
|
32
|
-
ex = nil
|
33
|
-
begin
|
34
|
-
establish_connection
|
35
|
-
result = yield
|
36
|
-
rescue => e
|
37
|
-
ex = e
|
38
|
-
ensure
|
39
|
-
establish_connection current_config
|
40
|
-
raise ex unless ex.nil?
|
41
|
-
result
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def name
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def global
|
54
|
-
global
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
|
1
|
+
module ActiveTenant
|
2
|
+
class SQLiteAdapter
|
3
|
+
delegate :connection_config, :establish_connection, :connection, to: ::ActiveRecord::Base
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.global = ActiveTenant.configuration.global if ActiveTenant.configuration.global
|
7
|
+
end
|
8
|
+
|
9
|
+
def all
|
10
|
+
path = database_path
|
11
|
+
Dir.glob("#{path}/*.sqlite3").map { |f| File.basename(f, '.sqlite3') } - [global]
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(name)
|
15
|
+
unless all.include? name
|
16
|
+
current_config = connection_config
|
17
|
+
establish_connection current_config.merge(database: file_name(name))
|
18
|
+
connection
|
19
|
+
establish_connection current_config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove(name)
|
24
|
+
file = file_name name
|
25
|
+
FileUtils.rm(file) if File.exist?(file)
|
26
|
+
end
|
27
|
+
|
28
|
+
def with(name)
|
29
|
+
return yield if name == self.name
|
30
|
+
|
31
|
+
current_config = connection_config
|
32
|
+
ex = nil
|
33
|
+
begin
|
34
|
+
establish_connection connection_settings(name)
|
35
|
+
result = yield
|
36
|
+
rescue => e
|
37
|
+
ex = e
|
38
|
+
ensure
|
39
|
+
establish_connection current_config
|
40
|
+
raise ex unless ex.nil?
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def connection_settings(name)
|
46
|
+
connection_config.merge(database: file_name(name))
|
47
|
+
end
|
48
|
+
|
49
|
+
def name
|
50
|
+
File.basename(connection_config[:database], '.sqlite3')
|
51
|
+
end
|
52
|
+
|
53
|
+
def global
|
54
|
+
@global
|
55
|
+
end
|
56
|
+
|
57
|
+
def global?
|
58
|
+
global == name
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def global=(name)
|
64
|
+
@global = name
|
65
|
+
end
|
66
|
+
|
67
|
+
def database_path
|
68
|
+
File.dirname(connection_config[:database])
|
69
|
+
end
|
70
|
+
|
71
|
+
def file_name(name)
|
72
|
+
"#{database_path}/#{name}.sqlite3"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
72
76
|
end
|