multibase-rails 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 637f656b14002267804eb509a4d96778690ff2c8
4
+ data.tar.gz: 51433b62e644647f01776c0cbd42b6240136fa02
5
+ SHA512:
6
+ metadata.gz: 965accf677c525a20284e0022dd61292263e7c2e2e36ee4118ff052ab1fd924aa14cb6895ed7936c09ed507c58ee31739d2a83eb30bf7bbe5aebe445ead2d6f9
7
+ data.tar.gz: 0249983088b8fa1e0474dcfb68fabe6f7e44adc3134326386acec6495c78d371ec989d86dcf99099519bcb830dbe2eb5b667369cb32d765cab4fc1ca478da837
data/.gitignore ADDED
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.2.2
6
+ before_install: gem install bundler -v 1.13.6
7
+ install:
8
+ - gem install bundler
9
+ - bundle --version
10
+ - bundle install
11
+ script:
12
+ - bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in multibase-rails.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,149 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ multibase-rails (0.1)
5
+ rails (>= 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.0.1)
11
+ actionpack (= 5.0.1)
12
+ nio4r (~> 1.2)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.0.1)
15
+ actionpack (= 5.0.1)
16
+ actionview (= 5.0.1)
17
+ activejob (= 5.0.1)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.0.1)
21
+ actionview (= 5.0.1)
22
+ activesupport (= 5.0.1)
23
+ rack (~> 2.0)
24
+ rack-test (~> 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.0.1)
28
+ activesupport (= 5.0.1)
29
+ builder (~> 3.1)
30
+ erubis (~> 2.7.0)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
+ activejob (5.0.1)
34
+ activesupport (= 5.0.1)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.0.1)
37
+ activesupport (= 5.0.1)
38
+ activerecord (5.0.1)
39
+ activemodel (= 5.0.1)
40
+ activesupport (= 5.0.1)
41
+ arel (~> 7.0)
42
+ activesupport (5.0.1)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ arel (7.1.4)
48
+ builder (3.2.3)
49
+ byebug (9.0.6)
50
+ coderay (1.1.1)
51
+ concurrent-ruby (1.0.5)
52
+ diff-lcs (1.2.5)
53
+ erubis (2.7.0)
54
+ globalid (0.3.7)
55
+ activesupport (>= 4.1.0)
56
+ i18n (0.8.1)
57
+ loofah (2.0.3)
58
+ nokogiri (>= 1.5.9)
59
+ mail (2.6.4)
60
+ mime-types (>= 1.16, < 4)
61
+ method_source (0.8.2)
62
+ mime-types (3.1)
63
+ mime-types-data (~> 3.2015)
64
+ mime-types-data (3.2016.0521)
65
+ mini_portile2 (2.1.0)
66
+ minitest (5.10.1)
67
+ nio4r (1.2.1)
68
+ nokogiri (1.7.0.1)
69
+ mini_portile2 (~> 2.1.0)
70
+ pg (0.19.0)
71
+ pry (0.10.4)
72
+ coderay (~> 1.1.0)
73
+ method_source (~> 0.8.1)
74
+ slop (~> 3.4)
75
+ pry-byebug (3.4.1)
76
+ byebug (~> 9.0)
77
+ pry (~> 0.10)
78
+ rack (2.0.1)
79
+ rack-test (0.6.3)
80
+ rack (>= 1.0)
81
+ rails (5.0.1)
82
+ actioncable (= 5.0.1)
83
+ actionmailer (= 5.0.1)
84
+ actionpack (= 5.0.1)
85
+ actionview (= 5.0.1)
86
+ activejob (= 5.0.1)
87
+ activemodel (= 5.0.1)
88
+ activerecord (= 5.0.1)
89
+ activesupport (= 5.0.1)
90
+ bundler (>= 1.3.0, < 2.0)
91
+ railties (= 5.0.1)
92
+ sprockets-rails (>= 2.0.0)
93
+ rails-dom-testing (2.0.2)
94
+ activesupport (>= 4.2.0, < 6.0)
95
+ nokogiri (~> 1.6)
96
+ rails-html-sanitizer (1.0.3)
97
+ loofah (~> 2.0)
98
+ railties (5.0.1)
99
+ actionpack (= 5.0.1)
100
+ activesupport (= 5.0.1)
101
+ method_source
102
+ rake (>= 0.8.7)
103
+ thor (>= 0.18.1, < 2.0)
104
+ rake (10.5.0)
105
+ rspec (3.5.0)
106
+ rspec-core (~> 3.5.0)
107
+ rspec-expectations (~> 3.5.0)
108
+ rspec-mocks (~> 3.5.0)
109
+ rspec-core (3.5.4)
110
+ rspec-support (~> 3.5.0)
111
+ rspec-expectations (3.5.0)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.5.0)
114
+ rspec-mocks (3.5.0)
115
+ diff-lcs (>= 1.2.0, < 2.0)
116
+ rspec-support (~> 3.5.0)
117
+ rspec-support (3.5.0)
118
+ slop (3.6.0)
119
+ sprockets (3.7.1)
120
+ concurrent-ruby (~> 1.0)
121
+ rack (> 1, < 3)
122
+ sprockets-rails (3.2.0)
123
+ actionpack (>= 4.0)
124
+ activesupport (>= 4.0)
125
+ sprockets (>= 3.0.0)
126
+ sqlite3 (1.3.13)
127
+ thor (0.19.4)
128
+ thread_safe (0.3.6)
129
+ tzinfo (1.2.2)
130
+ thread_safe (~> 0.1)
131
+ websocket-driver (0.6.5)
132
+ websocket-extensions (>= 0.1.0)
133
+ websocket-extensions (0.1.2)
134
+
135
+ PLATFORMS
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ bundler
140
+ multibase-rails!
141
+ pg
142
+ pry
143
+ pry-byebug
144
+ rake
145
+ rspec
146
+ sqlite3
147
+
148
+ BUNDLED WITH
149
+ 1.14.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Anatoly Nosov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Multibase [![Build Status](https://travis-ci.org/jomei/multibase.svg?branch=master)](https://travis-ci.org/jomei/multibase)
2
+ Multiple database support for Rails
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'multibase'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install multibase
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jomei/multibase. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
+
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run tasks tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Muiltibase'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+ module Multibase
4
+ class Base < ActiveRecord::Base
5
+ self.abstract_class = true
6
+
7
+ def self.using(database_key)
8
+ @database = database_key
9
+ Multibase.apply database_key.to_s
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ module Multibase
2
+ class Config
3
+ attr_reader :key
4
+
5
+ attr_reader :settings
6
+
7
+ def initialize(key, settings)
8
+ @key = key.to_s
9
+ @settings = HashWithIndifferentAccess.new(settings)
10
+ end
11
+
12
+ def db_root
13
+ @db_root ||= Rails.root.join('db').tap { |dir| FileUtils.mkdir_p dir }
14
+ end
15
+
16
+ def db_dir
17
+ @db_dir ||= db_root.join(key).tap { |dir| FileUtils.mkdir_p(dir) }
18
+ end
19
+
20
+ def db_migrate
21
+ @db_migrate ||= db_dir.join('migrate').tap { |dir| FileUtils.mkdir_p dir }
22
+ end
23
+
24
+ def db_seed
25
+ @db_seed ||= db_dir.join('seed.rb')
26
+ end
27
+
28
+ def load_seed
29
+ load(db_seed) if db_seed.exist?
30
+ end
31
+
32
+ def current_settings
33
+ settings[Rails.env]
34
+ end
35
+
36
+ def apply(new_settings = settings)
37
+ Rails.application.config.multibase.current_settings = new_settings
38
+ ActiveRecord::Base.configurations = new_settings
39
+ ActiveRecord::Base.establish_connection
40
+ connection_dir_path = Multibase::Railtie.fullpath(key)
41
+ migration_paths = [connection_dir_path.join('migrate')]
42
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = migration_paths
43
+ ActiveRecord::Tasks::DatabaseTasks.db_dir = connection_dir_path
44
+ ActiveRecord::Migrator.migrations_paths = migration_paths
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ module Multibase
2
+ mattr_accessor :connected, instance_accessor: false
3
+ self.connected = false
4
+
5
+ def self.exec(key)
6
+ # todo add key check
7
+ @config = Multibase::Config.new key, Multibase::Railtie.database_configuration[key]
8
+ @config.apply
9
+ yield
10
+ end
11
+ end
@@ -0,0 +1,67 @@
1
+ module Multibase
2
+ class Railtie < Rails::Railtie
3
+ config.multibase = ActiveSupport::OrderedOptions.new
4
+ config.multibase.db_dir = 'db'
5
+ config.multibase.path = 'config/database.yml'
6
+ config.multibase.default_key = 'default'
7
+
8
+ initializer 'multibase.handle_database_configuration',
9
+ before: 'active_record.initialize_database' do |app|
10
+
11
+ settings = app.config.database_configuration
12
+ config.multibase.settings = settings
13
+
14
+ app.config.define_singleton_method(:database_configuration) do
15
+ Rails.application.config.multibase.current_settings
16
+ end
17
+
18
+ Multibase.send(:reset).apply_default
19
+ end
20
+
21
+ config.after_initialize do |app|
22
+ multibases_dir = app.root.join(config.multibase.db_dir)
23
+ connection_keys.each do |name|
24
+ db_dir = multibases_dir.join name
25
+ FileUtils.mkdir_p(db_dir) unless File.directory?(db_dir)
26
+ end
27
+ end
28
+
29
+ def fullpath(extra=nil)
30
+ path = Rails.root.join(config.multibase.db_dir)
31
+ (extra ? path.join(path, extra) : path)
32
+ end
33
+
34
+ def connection_keys
35
+ self.class.database_configuration.keys
36
+ end
37
+
38
+ def connection?(name)
39
+ connection_keys.include? name
40
+ end
41
+
42
+ rake_tasks do
43
+ load 'multibase/tasks/database.rake'
44
+ end
45
+
46
+ generators do
47
+ require 'rails/multibase/generators/migration_generator'
48
+ end
49
+
50
+ def self.database_configuration
51
+ path = Rails.root.join config.multibase.path
52
+ yaml = Pathname.new(path) if path
53
+ @configuration ||= if yaml && yaml.exist?
54
+ require 'yaml'
55
+ require 'erb'
56
+ YAML.load(ERB.new(yaml.read).result) || {}
57
+ elsif ENV['DATABASE_URL']
58
+ # Value from ENV['DATABASE_URL'] is set to default database connection
59
+ # by Active Record.
60
+ {}
61
+ else
62
+ raise "Could not load database configuration. No such file - #{paths["config/database"].instance_variable_get(:@paths)}"
63
+ end
64
+ @configuration
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,150 @@
1
+ namespace :db do
2
+ keys = Multibase::Railtie.connection_keys
3
+ keys.each do |key|
4
+
5
+ namespace key.to_sym do
6
+
7
+ namespace :create do
8
+ task :all do
9
+ Multibase.exec(key) { Rake::Task['db:create:all'].execute }
10
+ end
11
+ end
12
+
13
+ task :create do
14
+ Multibase.exec(key) { Rake::Task['db:create'].execute }
15
+ end
16
+
17
+ task :drop => ['db:load_config'] do
18
+ Multibase.exec(key) { Rake::Task['db:drop'].execute }
19
+ end
20
+
21
+ namespace :drop do
22
+ task :all do
23
+ Multibase.exec(key) { Rake::Task['db:drop:all'].execute }
24
+ end
25
+ end
26
+
27
+ task :purge do
28
+ Multibase.exec(key) { Rake::Task['db:purge'].execute }
29
+ end
30
+
31
+ namespace :purge do
32
+ task :all do
33
+ Multibase.exec(key) { Rake::Task['db:purge:all'].execute }
34
+ end
35
+ end
36
+
37
+ task :migrate do
38
+ Multibase.exec(key) { Rake::Task['db:migrate'].execute }
39
+ end
40
+
41
+ namespace :migrate do
42
+ task :all do
43
+ Multibase.exec(key) { Rake::Task['db:migrate:all'].execute }
44
+ end
45
+ end
46
+
47
+ task :setup do
48
+ Multibase.exec(key) { Rake::Task['db:setup'].execute }
49
+ end
50
+
51
+ task :seed do
52
+ Multibase.exec(key) { Rake::Task['db:seed'].execute }
53
+ end
54
+
55
+ namespace :migrate do
56
+
57
+ task :redo => ['db:load_config'] do
58
+ Multibase.exec(key) { Rake::Task['db:migrate:redo'].execute }
59
+ end
60
+
61
+ task :up => ['db:load_config'] do
62
+ Multibase.exec(key) { Rake::Task['db:migrate:up'].execute }
63
+ end
64
+
65
+ task :down => ['db:load_config'] do
66
+ Multibase.exec(key) { Rake::Task['db:migrate:down'].execute }
67
+ end
68
+
69
+ task :status => ['db:load_config'] do
70
+ Multibase.exec(key) { Rake::Task['db:migrate:status'].execute }
71
+ end
72
+
73
+ end
74
+
75
+ task :rollback => ['db:load_config'] do
76
+ Multibase.exec(key) { Rake::Task['db:rollback'].execute }
77
+ end
78
+
79
+ task :forward => ['db:load_config'] do
80
+ Multibase.exec(key) { Rake::Task['db:forward'].execute }
81
+ end
82
+
83
+ task :abort_if_pending_migrations do
84
+ Multibase.exec(key) { Rake::Task['db:abort_if_pending_migrations'].execute }
85
+ end
86
+
87
+ task :version => ['db:load_config'] do
88
+ Multibase.exec(key) { Rake::Task['db:version'].execute }
89
+ end
90
+
91
+ namespace :schema do
92
+
93
+ task :load do
94
+ Multibase.exec(key) { Rake::Task['db:schema:load'].execute }
95
+ end
96
+
97
+ namespace :cache do
98
+
99
+ task :dump do
100
+ Multibase.exec(key) { Rake::Task['db:schema:cache:dump'].execute }
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+
107
+ namespace :structure do
108
+
109
+ task :load do
110
+ Multibase.exec(key) { Rake::Task['db:structure:load'].execute }
111
+ end
112
+
113
+ end
114
+
115
+ namespace :test do
116
+
117
+ task :purge do
118
+ Multibase.exec(key) { Rake::Task['db:test:purge'].execute }
119
+ end
120
+
121
+ task :load_schema do
122
+ Multibase.exec(key) { Rake::Task['db:test:load_schema'].execute }
123
+ end
124
+
125
+ task :load_structure do
126
+ Multibase.exec(key) { Rake::Task['db:test:load_structure'].execute }
127
+ end
128
+
129
+ task :prepare do
130
+ Multibase.exec(key) { Rake::Task['db:test:prepare'].execute }
131
+ end
132
+ end
133
+
134
+ end
135
+ end
136
+ end
137
+
138
+ %w{
139
+ create:all create drop:all drop purge:all purge
140
+ migrate migrate:status abort_if_pending_migrations
141
+ schema:load schema:cache:dump structure:load setup seed
142
+ test:purge test:load_schema test:load_structure test:prepare
143
+ }.each do |name|
144
+ task = Rake::Task["db:#{name}"]
145
+ next unless task
146
+
147
+ task.enhance do
148
+ Rake::Task["db:load_config"].invoke
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ module Multibase
2
+ VERSION = '0.1'
3
+ end
data/lib/multibase.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'rails'
2
+
3
+ module Multibase
4
+ require_relative 'multibase/config'
5
+ require_relative 'multibase/railtie'
6
+ require_relative 'multibase/exec'
7
+ require_relative 'multibase/base'
8
+
9
+ class << self
10
+ include Enumerable
11
+ delegate :each, :[], :keys, to: :@config
12
+
13
+ attr_reader :settings
14
+
15
+ attr_reader :default_key
16
+
17
+ def reset
18
+ Rails.application.config.multibase.tap do |config|
19
+ @default_key = config.default_key
20
+ @settings = HashWithIndifferentAccess.new(config.settings)
21
+ end
22
+
23
+ @config = settings
24
+ .each_with_object(HashWithIndifferentAccess.new) do |(key, val), hash|
25
+ hash[key] = Config.new(key, val)
26
+ end
27
+
28
+ self
29
+ end
30
+
31
+ def apply_default
32
+ apply default_key
33
+ end
34
+
35
+ def apply(key)
36
+ tap { |db| db[key].apply }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+ require 'rails/generators/active_record/migration/migration_generator'
4
+
5
+ module Multibase
6
+ class MigrationGenerator < ActiveRecord::Generators::MigrationGenerator
7
+ source_root ActiveRecord::Generators::MigrationGenerator.source_root
8
+
9
+ def self.desc
10
+ require 'rails/generators/rails/migration/migration_generator'
11
+ Rails::Generators::MigrationGenerator.desc
12
+ end
13
+
14
+ def create_migration_file
15
+ @connection_name = attributes.first.name
16
+ unless Multibase::Railtie.connection? @connection_name
17
+ raise ArgumentError.new "Connection #{@connection_name} not found"
18
+ end
19
+ attributes.shift
20
+ super
21
+ end
22
+
23
+ include(Module.new{
24
+
25
+ def migration_template(*args)
26
+ args[1].sub! 'db/migrate', "db/#{@connection_name}/migrate" if args[1]
27
+ super(*args)
28
+ end
29
+
30
+ })
31
+
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'multibase/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'multibase-rails'
8
+ spec.version = Multibase::VERSION
9
+ spec.authors = ['Anatoly Nosov']
10
+ spec.email = ['jomeisama@gmail.com']
11
+
12
+ spec.summary = %q{Rails multiple database support}
13
+ spec.description = 'Multibase provides support for Rails to manage several databases by extending ActiveRecord tasks that create, migrate, and test your databases.'
14
+ spec.homepage = 'https://github.com/jomei/multibase'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'rails', '>= 4.0'
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'pry-byebug'
30
+ spec.add_development_dependency 'sqlite3'
31
+ spec.add_development_dependency 'pg'
32
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multibase-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Anatoly Nosov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Multibase provides support for Rails to manage several databases by extending
126
+ ActiveRecord tasks that create, migrate, and test your databases.
127
+ email:
128
+ - jomeisama@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - lib/multibase.rb
142
+ - lib/multibase/base.rb
143
+ - lib/multibase/config.rb
144
+ - lib/multibase/exec.rb
145
+ - lib/multibase/railtie.rb
146
+ - lib/multibase/tasks/database.rake
147
+ - lib/multibase/version.rb
148
+ - lib/rails/multibase/generators/migration_generator.rb
149
+ - multibase-rails.gemspec
150
+ homepage: https://github.com/jomei/multibase
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.6.10
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Rails multiple database support
174
+ test_files: []