multibase-rails 0.1 → 0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 637f656b14002267804eb509a4d96778690ff2c8
4
- data.tar.gz: 51433b62e644647f01776c0cbd42b6240136fa02
3
+ metadata.gz: a2c76e1338205c8ba6b875118dd85aee1ee16f64
4
+ data.tar.gz: f0b1578faf1a40d41576a8f224e3df9e0770219d
5
5
  SHA512:
6
- metadata.gz: 965accf677c525a20284e0022dd61292263e7c2e2e36ee4118ff052ab1fd924aa14cb6895ed7936c09ed507c58ee31739d2a83eb30bf7bbe5aebe445ead2d6f9
7
- data.tar.gz: 0249983088b8fa1e0474dcfb68fabe6f7e44adc3134326386acec6495c78d371ec989d86dcf99099519bcb830dbe2eb5b667369cb32d765cab4fc1ca478da837
6
+ metadata.gz: 5290d48dbbc5e58abb735e9d07d41c5eb38957d05d3e4231727dc5ad9b860237dbbcdeb734ae7ad4322a7d5ce925dcaa942bc98ef4cd63c1df28d9d806775ac6
7
+ data.tar.gz: 7b26870a0a5e5dcb936b4876eafced4bb8bf0ef7dbcbfec2604ebf9c205ecd0416f843b3e23c485ca689d974c6b701d785f0fa0993d0f7d1fae1dabd531697cb
data/.gitignore CHANGED
@@ -9,6 +9,7 @@
9
9
  /test/tmp/
10
10
  /test/version_tmp/
11
11
  /tmp/
12
+ /coverage
12
13
 
13
14
  # Used by dotenv library to load environment variables.
14
15
  # .env
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ StyleGuideCopsOnly: true
5
+ TargetRubyVersion: 2.2
6
+
7
+ Metrics/LineLength:
8
+ Max: 100
9
+
10
+ Bundler/DuplicatedGem:
11
+ Enabled: false
12
+
13
+ Style/CaseEquality:
14
+ Enabled: false
15
+
16
+ Style/ClassVars:
17
+ Enabled: false
18
+
19
+ Style/ClassAndModuleChildren:
20
+ Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/DoubleNegation:
26
+ Enabled: false
27
+
28
+ Style/FileName:
29
+ Exclude:
30
+ - lib/dry-initializer.rb
31
+
32
+ Style/Lambda:
33
+ Exclude:
34
+ - spec/**/*_spec.rb
35
+
36
+ Style/LambdaCall:
37
+ Enabled: false
38
+
39
+ Style/RaiseArgs:
40
+ EnforcedStyle: compact
41
+
42
+ Style/Semicolon:
43
+ Exclude:
44
+ - spec/**/*_spec.rb
45
+
46
+ Style/SignalException:
47
+ EnforcedStyle: semantic
48
+
49
+ Style/StringLiterals:
50
+ EnforcedStyle: single_quotes
51
+
52
+ Style/StringLiteralsInInterpolation:
53
+ EnforcedStyle: double_quotes
data/.simplecov ADDED
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start do
6
+ add_filter 'test/'
7
+ end
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rubocop', '~> 0.42'
4
+ gem 'coveralls', require: false, group: :test
5
+ gem 'simplecov', require: false, group: :test
3
6
  # Specify your gem's dependencies in multibase-rails.gemspec
4
7
  gemspec
data/Gemfile.lock CHANGED
@@ -1,59 +1,68 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- multibase-rails (0.1)
4
+ multibase-rails (0.2)
5
5
  rails (>= 4.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (5.0.1)
11
- actionpack (= 5.0.1)
12
- nio4r (~> 1.2)
10
+ actioncable (5.0.2)
11
+ actionpack (= 5.0.2)
12
+ nio4r (>= 1.2, < 3.0)
13
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)
14
+ actionmailer (5.0.2)
15
+ actionpack (= 5.0.2)
16
+ actionview (= 5.0.2)
17
+ activejob (= 5.0.2)
18
18
  mail (~> 2.5, >= 2.5.4)
19
19
  rails-dom-testing (~> 2.0)
20
- actionpack (5.0.1)
21
- actionview (= 5.0.1)
22
- activesupport (= 5.0.1)
20
+ actionpack (5.0.2)
21
+ actionview (= 5.0.2)
22
+ activesupport (= 5.0.2)
23
23
  rack (~> 2.0)
24
24
  rack-test (~> 0.6.3)
25
25
  rails-dom-testing (~> 2.0)
26
26
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.0.1)
28
- activesupport (= 5.0.1)
27
+ actionview (5.0.2)
28
+ activesupport (= 5.0.2)
29
29
  builder (~> 3.1)
30
30
  erubis (~> 2.7.0)
31
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)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.0.2)
34
+ activesupport (= 5.0.2)
35
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)
36
+ activemodel (5.0.2)
37
+ activesupport (= 5.0.2)
38
+ activerecord (5.0.2)
39
+ activemodel (= 5.0.2)
40
+ activesupport (= 5.0.2)
41
41
  arel (~> 7.0)
42
- activesupport (5.0.1)
42
+ activesupport (5.0.2)
43
43
  concurrent-ruby (~> 1.0, >= 1.0.2)
44
44
  i18n (~> 0.7)
45
45
  minitest (~> 5.1)
46
46
  tzinfo (~> 1.1)
47
47
  arel (7.1.4)
48
+ ast (2.3.0)
48
49
  builder (3.2.3)
49
50
  byebug (9.0.6)
50
51
  coderay (1.1.1)
51
52
  concurrent-ruby (1.0.5)
53
+ coveralls (0.8.19)
54
+ json (>= 1.8, < 3)
55
+ simplecov (~> 0.12.0)
56
+ term-ansicolor (~> 1.3)
57
+ thor (~> 0.19.1)
58
+ tins (~> 1.6)
52
59
  diff-lcs (1.2.5)
60
+ docile (1.1.5)
53
61
  erubis (2.7.0)
54
62
  globalid (0.3.7)
55
63
  activesupport (>= 4.1.0)
56
64
  i18n (0.8.1)
65
+ json (2.0.3)
57
66
  loofah (2.0.3)
58
67
  nokogiri (>= 1.5.9)
59
68
  mail (2.6.4)
@@ -64,10 +73,12 @@ GEM
64
73
  mime-types-data (3.2016.0521)
65
74
  mini_portile2 (2.1.0)
66
75
  minitest (5.10.1)
67
- nio4r (1.2.1)
76
+ nio4r (2.0.0)
68
77
  nokogiri (1.7.0.1)
69
78
  mini_portile2 (~> 2.1.0)
70
- pg (0.19.0)
79
+ parser (2.3.3.1)
80
+ ast (~> 2.2)
81
+ powerpack (0.1.1)
71
82
  pry (0.10.4)
72
83
  coderay (~> 1.1.0)
73
84
  method_source (~> 0.8.1)
@@ -78,29 +89,30 @@ GEM
78
89
  rack (2.0.1)
79
90
  rack-test (0.6.3)
80
91
  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)
92
+ rails (5.0.2)
93
+ actioncable (= 5.0.2)
94
+ actionmailer (= 5.0.2)
95
+ actionpack (= 5.0.2)
96
+ actionview (= 5.0.2)
97
+ activejob (= 5.0.2)
98
+ activemodel (= 5.0.2)
99
+ activerecord (= 5.0.2)
100
+ activesupport (= 5.0.2)
90
101
  bundler (>= 1.3.0, < 2.0)
91
- railties (= 5.0.1)
102
+ railties (= 5.0.2)
92
103
  sprockets-rails (>= 2.0.0)
93
104
  rails-dom-testing (2.0.2)
94
105
  activesupport (>= 4.2.0, < 6.0)
95
106
  nokogiri (~> 1.6)
96
107
  rails-html-sanitizer (1.0.3)
97
108
  loofah (~> 2.0)
98
- railties (5.0.1)
99
- actionpack (= 5.0.1)
100
- activesupport (= 5.0.1)
109
+ railties (5.0.2)
110
+ actionpack (= 5.0.2)
111
+ activesupport (= 5.0.2)
101
112
  method_source
102
113
  rake (>= 0.8.7)
103
114
  thor (>= 0.18.1, < 2.0)
115
+ rainbow (2.1.0)
104
116
  rake (10.5.0)
105
117
  rspec (3.5.0)
106
118
  rspec-core (~> 3.5.0)
@@ -115,6 +127,18 @@ GEM
115
127
  diff-lcs (>= 1.2.0, < 2.0)
116
128
  rspec-support (~> 3.5.0)
117
129
  rspec-support (3.5.0)
130
+ rubocop (0.46.0)
131
+ parser (>= 2.3.1.1, < 3.0)
132
+ powerpack (~> 0.1)
133
+ rainbow (>= 1.99.1, < 3.0)
134
+ ruby-progressbar (~> 1.7)
135
+ unicode-display_width (~> 1.0, >= 1.0.1)
136
+ ruby-progressbar (1.8.1)
137
+ simplecov (0.12.0)
138
+ docile (~> 1.1.0)
139
+ json (>= 1.8, < 3)
140
+ simplecov-html (~> 0.10.0)
141
+ simplecov-html (0.10.0)
118
142
  slop (3.6.0)
119
143
  sprockets (3.7.1)
120
144
  concurrent-ruby (~> 1.0)
@@ -124,10 +148,14 @@ GEM
124
148
  activesupport (>= 4.0)
125
149
  sprockets (>= 3.0.0)
126
150
  sqlite3 (1.3.13)
151
+ term-ansicolor (1.4.0)
152
+ tins (~> 1.0)
127
153
  thor (0.19.4)
128
154
  thread_safe (0.3.6)
155
+ tins (1.13.2)
129
156
  tzinfo (1.2.2)
130
157
  thread_safe (~> 0.1)
158
+ unicode-display_width (1.1.2)
131
159
  websocket-driver (0.6.5)
132
160
  websocket-extensions (>= 0.1.0)
133
161
  websocket-extensions (0.1.2)
@@ -137,13 +165,15 @@ PLATFORMS
137
165
 
138
166
  DEPENDENCIES
139
167
  bundler
168
+ coveralls
140
169
  multibase-rails!
141
- pg
142
170
  pry
143
171
  pry-byebug
144
172
  rake
145
173
  rspec
174
+ rubocop (~> 0.42)
175
+ simplecov
146
176
  sqlite3
147
177
 
148
178
  BUNDLED WITH
149
- 1.14.2
179
+ 1.14.6
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # Multibase [![Build Status](https://travis-ci.org/jomei/multibase.svg?branch=master)](https://travis-ci.org/jomei/multibase)
1
+ # Multibase [![Build Status](https://travis-ci.org/jomei/multibase.svg?branch=master)](https://travis-ci.org/jomei/multibase) [![Coverage Status](https://coveralls.io/repos/github/jomei/multibase/badge.svg?branch=master)](https://coveralls.io/github/jomei/multibase?branch=master) [![Code Climate](https://lima.codeclimate.com/github/jomei/multibase/badges/gpa.svg)](https://lima.codeclimate.com/github/jomei/multibase)
2
2
  Multiple database support for Rails
3
3
  ## Installation
4
4
 
5
5
  Add this line to your application's Gemfile:
6
6
 
7
7
  ```ruby
8
- gem 'multibase'
8
+ gem 'multibase-rails'
9
9
  ```
10
10
 
11
11
  And then execute:
@@ -14,22 +14,64 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install multibase
17
+ $ gem install multibase-rails
18
18
 
19
19
  ## Usage
20
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
21
+ ### database.yml
22
+ Change config/database.yml so that settings for every database are placed under the following root key:
23
+ ```yaml
24
+ # config/database.yml
25
+ ---
26
+ default: # default key for the default database
27
+ test:
28
+ adapter: sqlite3
29
+ url: ./base/test.sqlite3
30
+ development:
31
+ adapter: sqlite3
32
+ url: ./base/development.sqlite3
33
+ production:
34
+ adapter: postgresql
35
+ url: <%= ENV['DEFAULT_BASE_URL'] %>
36
+ custom_db: # the unique name for another database
37
+ test:
38
+ adapter: sqlite3
39
+ url: ./custom_db/test.sqlite3
40
+ development:
41
+ adapter: sqlite3
42
+ url: ./custom_db/development.sqlite3
43
+ production:
44
+ adapter: postgresql
45
+ url: <%= ENV['PERSONAL_BASE_URL'] %>
46
+ ```
47
+ ### Configurations
48
+ You can define your own default database key in `config/application.rb`
49
+ ```
50
+ config.multibase.default_key # Default: 'default'
51
+ ```
30
52
 
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.
53
+ ### Rake tasks
54
+ All `db:` rake tasks defined for each database as `db:your_database_name:command`, e.g. `rake db:cusom_db:create`
32
55
 
56
+ ### Rails Generators
57
+ #### Migrations
58
+ Use `multibase:migration` to generate migration for specific database
59
+ ```
60
+ rails g multibase:migration <migration_name> <database_name> <options>
61
+ ```
62
+ Example
63
+ ```ruby
64
+ rails g multibase:migration CreateMyTable custom_db foo:integer baz:string
65
+ ```
66
+ ### Rails models
67
+ All models should be inherit from `Multibase::Base`.
68
+ Use `using` method to specify database connection
69
+ Example
70
+ ```ruby
71
+ class Comment < Multibase::Base
72
+ using :my_not_default_connection
73
+ end
74
+ ```
33
75
 
34
76
  ## License
35
77
 
data/Rakefile CHANGED
@@ -14,9 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
-
20
17
  Bundler::GemHelper.install_tasks
21
18
 
22
19
  require 'rake/testtask'
@@ -28,5 +25,4 @@ Rake::TestTask.new(:test) do |t|
28
25
  t.verbose = false
29
26
  end
30
27
 
31
-
32
28
  task default: :test
data/lib/multibase.rb CHANGED
@@ -11,7 +11,6 @@ module Multibase
11
11
  delegate :each, :[], :keys, to: :@config
12
12
 
13
13
  attr_reader :settings
14
-
15
14
  attr_reader :default_key
16
15
 
17
16
  def reset
@@ -20,11 +19,11 @@ module Multibase
20
19
  @settings = HashWithIndifferentAccess.new(config.settings)
21
20
  end
22
21
 
23
- @config = settings
24
- .each_with_object(HashWithIndifferentAccess.new) do |(key, val), hash|
22
+ @config = settings.each_with_object(
23
+ HashWithIndifferentAccess.new
24
+ ) do |(key, val), hash|
25
25
  hash[key] = Config.new(key, val)
26
26
  end
27
-
28
27
  self
29
28
  end
30
29
 
@@ -33,7 +32,8 @@ module Multibase
33
32
  end
34
33
 
35
34
  def apply(key)
36
- tap { |db| db[key].apply }
35
+ @config[key].apply
37
36
  end
37
+
38
38
  end
39
- end
39
+ end
@@ -4,9 +4,9 @@ module Multibase
4
4
  class Base < ActiveRecord::Base
5
5
  self.abstract_class = true
6
6
 
7
- def self.using(database_key)
7
+ def self.using(database_key = Multibase.default_key)
8
8
  @database = database_key
9
9
  Multibase.apply database_key.to_s
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -36,12 +36,13 @@ module Multibase
36
36
  def apply(new_settings = settings)
37
37
  Rails.application.config.multibase.current_settings = new_settings
38
38
  ActiveRecord::Base.configurations = new_settings
39
- ActiveRecord::Base.establish_connection
39
+ ActiveRecord::Tasks::DatabaseTasks.current_config = new_settings
40
40
  connection_dir_path = Multibase::Railtie.fullpath(key)
41
41
  migration_paths = [connection_dir_path.join('migrate')]
42
42
  ActiveRecord::Tasks::DatabaseTasks.migrations_paths = migration_paths
43
43
  ActiveRecord::Tasks::DatabaseTasks.db_dir = connection_dir_path
44
44
  ActiveRecord::Migrator.migrations_paths = migration_paths
45
+ ActiveRecord::Base.establish_connection new_settings[Rails.env]
45
46
  end
46
47
  end
47
- end
48
+ end
@@ -1,11 +1,11 @@
1
1
  module Multibase
2
2
  mattr_accessor :connected, instance_accessor: false
3
- self.connected = false
4
3
 
5
4
  def self.exec(key)
6
- # todo add key check
7
- @config = Multibase::Config.new key, Multibase::Railtie.database_configuration[key]
8
- @config.apply
5
+ if @config.nil? || @config.key != key
6
+ @config = Multibase::Config.new key, Multibase::Railtie.database_configuration[key]
7
+ @config.apply
8
+ end
9
9
  yield
10
10
  end
11
- end
11
+ end
@@ -9,6 +9,13 @@ module Multibase
9
9
  before: 'active_record.initialize_database' do |app|
10
10
 
11
11
  settings = app.config.database_configuration
12
+ # Checks whether default settings exist
13
+ default_settings = settings[config.multibase.default_key]
14
+ fail <<-TEXT.gsub(/ +\|/, '') unless default_settings
15
+ |Default database configuration has not been defined yet.
16
+ |You should either add settings to the `config/database.yml` under the key :#{config.multibase.default_key},
17
+ |or assign another value to `config.data_bases.default_key` in `config/application.rb`.
18
+ TEXT
12
19
  config.multibase.settings = settings
13
20
 
14
21
  app.config.define_singleton_method(:database_configuration) do
@@ -18,6 +25,13 @@ module Multibase
18
25
  Multibase.send(:reset).apply_default
19
26
  end
20
27
 
28
+ initializer 'multibase.add_watchable_files' do |app|
29
+ connection_keys.each do |connection|
30
+ dir = app.root.join(config.multibase.db_dir, connection)
31
+ config.watchable_files.concat ["#{dir}/schema.rb", "#{dir}/structure.sql"]
32
+ end
33
+ end
34
+
21
35
  config.after_initialize do |app|
22
36
  multibases_dir = app.root.join(config.multibase.db_dir)
23
37
  connection_keys.each do |name|
@@ -26,7 +40,7 @@ module Multibase
26
40
  end
27
41
  end
28
42
 
29
- def fullpath(extra=nil)
43
+ def fullpath(extra = nil)
30
44
  path = Rails.root.join(config.multibase.db_dir)
31
45
  (extra ? path.join(path, extra) : path)
32
46
  end
@@ -51,17 +65,19 @@ module Multibase
51
65
  path = Rails.root.join config.multibase.path
52
66
  yaml = Pathname.new(path) if path
53
67
  @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
68
+ require 'yaml'
69
+ require 'erb'
70
+ YAML.load(ERB.new(yaml.read).result) || {}
71
+ elsif ENV['DATABASE_URL']
72
+ # Value from ENV['DATABASE_URL'] is set to default database connection
73
+ # by Active Record.
74
+ {}
75
+ else
76
+ raise "Could not load database configuration.
77
+ No such file - #{paths["config/database"].instance_variable_get(:@paths)}"
78
+ end
64
79
  @configuration
65
80
  end
81
+
66
82
  end
67
- end
83
+ end
@@ -1,9 +1,7 @@
1
1
  namespace :db do
2
2
  keys = Multibase::Railtie.connection_keys
3
3
  keys.each do |key|
4
-
5
4
  namespace key.to_sym do
6
-
7
5
  namespace :create do
8
6
  task :all do
9
7
  Multibase.exec(key) { Rake::Task['db:create:all'].execute }
@@ -14,7 +12,7 @@ namespace :db do
14
12
  Multibase.exec(key) { Rake::Task['db:create'].execute }
15
13
  end
16
14
 
17
- task :drop => ['db:load_config'] do
15
+ task drop: ['db:load_config'] do
18
16
  Multibase.exec(key) { Rake::Task['db:drop'].execute }
19
17
  end
20
18
 
@@ -53,30 +51,28 @@ namespace :db do
53
51
  end
54
52
 
55
53
  namespace :migrate do
56
-
57
- task :redo => ['db:load_config'] do
54
+ task redo: ['db:load_config'] do
58
55
  Multibase.exec(key) { Rake::Task['db:migrate:redo'].execute }
59
56
  end
60
57
 
61
- task :up => ['db:load_config'] do
58
+ task up: ['db:load_config'] do
62
59
  Multibase.exec(key) { Rake::Task['db:migrate:up'].execute }
63
60
  end
64
61
 
65
- task :down => ['db:load_config'] do
62
+ task down: ['db:load_config'] do
66
63
  Multibase.exec(key) { Rake::Task['db:migrate:down'].execute }
67
64
  end
68
65
 
69
- task :status => ['db:load_config'] do
66
+ task status: ['db:load_config'] do
70
67
  Multibase.exec(key) { Rake::Task['db:migrate:status'].execute }
71
68
  end
72
-
73
69
  end
74
70
 
75
- task :rollback => ['db:load_config'] do
71
+ task rollback: ['db:load_config'] do
76
72
  Multibase.exec(key) { Rake::Task['db:rollback'].execute }
77
73
  end
78
74
 
79
- task :forward => ['db:load_config'] do
75
+ task forward: ['db:load_config'] do
80
76
  Multibase.exec(key) { Rake::Task['db:forward'].execute }
81
77
  end
82
78
 
@@ -84,36 +80,29 @@ namespace :db do
84
80
  Multibase.exec(key) { Rake::Task['db:abort_if_pending_migrations'].execute }
85
81
  end
86
82
 
87
- task :version => ['db:load_config'] do
83
+ task version: ['db:load_config'] do
88
84
  Multibase.exec(key) { Rake::Task['db:version'].execute }
89
85
  end
90
86
 
91
87
  namespace :schema do
92
-
93
88
  task :load do
94
89
  Multibase.exec(key) { Rake::Task['db:schema:load'].execute }
95
90
  end
96
91
 
97
92
  namespace :cache do
98
-
99
93
  task :dump do
100
94
  Multibase.exec(key) { Rake::Task['db:schema:cache:dump'].execute }
101
95
  end
102
-
103
96
  end
104
-
105
97
  end
106
98
 
107
99
  namespace :structure do
108
-
109
100
  task :load do
110
101
  Multibase.exec(key) { Rake::Task['db:structure:load'].execute }
111
102
  end
112
-
113
103
  end
114
104
 
115
105
  namespace :test do
116
-
117
106
  task :purge do
118
107
  Multibase.exec(key) { Rake::Task['db:test:purge'].execute }
119
108
  end
@@ -130,21 +119,20 @@ namespace :db do
130
119
  Multibase.exec(key) { Rake::Task['db:test:prepare'].execute }
131
120
  end
132
121
  end
133
-
134
122
  end
135
123
  end
136
124
  end
137
125
 
138
- %w{
126
+ %w(
139
127
  create:all create drop:all drop purge:all purge
140
128
  migrate migrate:status abort_if_pending_migrations
141
129
  schema:load schema:cache:dump structure:load setup seed
142
130
  test:purge test:load_schema test:load_structure test:prepare
143
- }.each do |name|
131
+ ).each do |name|
144
132
  task = Rake::Task["db:#{name}"]
145
133
  next unless task
146
134
 
147
135
  task.enhance do
148
- Rake::Task["db:load_config"].invoke
136
+ Rake::Task['db:load_config'].invoke
149
137
  end
150
- end
138
+ end
@@ -1,3 +1,3 @@
1
1
  module Multibase
2
- VERSION = '0.1'
2
+ VERSION = '0.2'.freeze
3
3
  end
@@ -13,21 +13,22 @@ module Multibase
13
13
 
14
14
  def create_migration_file
15
15
  @connection_name = attributes.first.name
16
- unless Multibase::Railtie.connection? @connection_name
17
- raise ArgumentError.new "Connection #{@connection_name} not found"
16
+ if Multibase::Railtie.connection? @connection_name
17
+ attributes.shift
18
+ else
19
+ @connection_name = Multibase.default_key
18
20
  end
19
- attributes.shift
20
21
  super
21
22
  end
22
23
 
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
- })
24
+ include(
25
+ Module.new do
26
+ def migration_template(*args)
27
+ args[1].sub! 'db/migrate', "db/#{@connection_name}/migrate" if args[1]
28
+ super(*args)
29
+ end
30
+ end
31
+ )
31
32
 
32
33
  end
33
- end
34
+ end
@@ -9,12 +9,14 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Anatoly Nosov']
10
10
  spec.email = ['jomeisama@gmail.com']
11
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.'
12
+ spec.summary = 'Rails multiple database support'
13
+ spec.description = 'Multibase provides support for Rails to manage several
14
+ databases by extending ActiveRecord tasks that create, migrate,
15
+ and test your databases'
14
16
  spec.homepage = 'https://github.com/jomei/multibase'
15
17
  spec.license = 'MIT'
16
18
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
19
21
  end
20
22
 
@@ -28,5 +30,5 @@ Gem::Specification.new do |spec|
28
30
  spec.add_development_dependency 'pry'
29
31
  spec.add_development_dependency 'pry-byebug'
30
32
  spec.add_development_dependency 'sqlite3'
31
- spec.add_development_dependency 'pg'
33
+
32
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multibase-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Nosov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,22 +108,10 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
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.
111
+ description: |-
112
+ Multibase provides support for Rails to manage several
113
+ databases by extending ActiveRecord tasks that create, migrate,
114
+ and test your databases
127
115
  email:
128
116
  - jomeisama@gmail.com
129
117
  executables: []
@@ -132,6 +120,8 @@ extra_rdoc_files: []
132
120
  files:
133
121
  - ".gitignore"
134
122
  - ".rspec"
123
+ - ".rubocop.yml"
124
+ - ".simplecov"
135
125
  - ".travis.yml"
136
126
  - Gemfile
137
127
  - Gemfile.lock