multibase-rails 0.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2c76e1338205c8ba6b875118dd85aee1ee16f64
4
- data.tar.gz: f0b1578faf1a40d41576a8f224e3df9e0770219d
3
+ metadata.gz: 2df22da87cc57c6add9a7739e9f44da3e4b69d85
4
+ data.tar.gz: f6bc21988c1f37da21c131fb54b43b396bed873e
5
5
  SHA512:
6
- metadata.gz: 5290d48dbbc5e58abb735e9d07d41c5eb38957d05d3e4231727dc5ad9b860237dbbcdeb734ae7ad4322a7d5ce925dcaa942bc98ef4cd63c1df28d9d806775ac6
7
- data.tar.gz: 7b26870a0a5e5dcb936b4876eafced4bb8bf0ef7dbcbfec2604ebf9c205ecd0416f843b3e23c485ca689d974c6b701d785f0fa0993d0f7d1fae1dabd531697cb
6
+ metadata.gz: 479fb150fe878745ef156510c7ba6de96cdb060f5b503a2da649d21d05013445af5c6598a459a3c3c0bddbecf64cdb640ae14870090f805c33d861bf9d93720c
7
+ data.tar.gz: 82593ff3f4c292229e5d5d979ad7e14b501a291074d3a6ca26bd3ae26166c22013afc7ce6bc4cfaa40d961de67a716ec1260cddfa780072c348aae1e5c10f383
data/LICENSE CHANGED
@@ -1,5 +1,6 @@
1
1
  The MIT License (MIT)
2
-
2
+ Copyright (c) 2010 Karle Durante
3
+ Copyright (c) 2016 CustomInk.com
3
4
  Copyright (c) 2017 Anatoly Nosov
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
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
- Multiple database support for Rails
2
+ Multiple database support for Rails.
3
+
4
+ This solution inspired by the [SecondBase](https://github.com/customink/secondbase)
3
5
  ## Installation
4
6
 
5
7
  Add this line to your application's Gemfile:
data/lib/multibase.rb CHANGED
@@ -36,4 +36,4 @@ module Multibase
36
36
  end
37
37
 
38
38
  end
39
- end
39
+ end
@@ -2,10 +2,10 @@ module Multibase
2
2
  mattr_accessor :connected, instance_accessor: false
3
3
 
4
4
  def self.exec(key)
5
- if @config.nil? || @config.key != key
6
- @config = Multibase::Config.new key, Multibase::Railtie.database_configuration[key]
7
- @config.apply
8
- end
5
+ config = @config[key] if @config
6
+ config ||= Multibase::Config.new key, Multibase::Railtie.database_configuration[key]
7
+ config.apply
8
+
9
9
  yield
10
10
  end
11
11
  end
@@ -62,21 +62,18 @@ module Multibase
62
62
  end
63
63
 
64
64
  def self.database_configuration
65
+ @configuration ||= Rails.application.config.multibase.settings || load_configuration
66
+ @configuration
67
+ end
68
+
69
+ def self.load_configuration
65
70
  path = Rails.root.join config.multibase.path
66
71
  yaml = Pathname.new(path) if path
67
- @configuration ||= if yaml && yaml.exist?
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
79
- @configuration
72
+ if yaml && yaml.exist?
73
+ require 'yaml'
74
+ require 'erb'
75
+ YAML.load(ERB.new(yaml.read).result) || {}
76
+ end
80
77
  end
81
78
 
82
79
  end
@@ -89,6 +89,10 @@ namespace :db do
89
89
  Multibase.exec(key) { Rake::Task['db:schema:load'].execute }
90
90
  end
91
91
 
92
+ task :dump do
93
+ Multibase.exec(key) { Rake::Task['db:schema:dump'].execute }
94
+ end
95
+
92
96
  namespace :cache do
93
97
  task :dump do
94
98
  Multibase.exec(key) { Rake::Task['db:schema:cache:dump'].execute }
@@ -126,7 +130,7 @@ end
126
130
  %w(
127
131
  create:all create drop:all drop purge:all purge
128
132
  migrate migrate:status abort_if_pending_migrations
129
- schema:load schema:cache:dump structure:load setup seed
133
+ schema:dump schema:load schema:cache:dump structure:load setup seed
130
134
  test:purge test:load_schema test:load_structure test:prepare
131
135
  ).each do |name|
132
136
  task = Rake::Task["db:#{name}"]
@@ -134,5 +138,8 @@ end
134
138
 
135
139
  task.enhance do
136
140
  Rake::Task['db:load_config'].invoke
141
+ Multibase::Railtie.connection_keys.each do |connection|
142
+ Rake::Task["db:#{connection}:#{name}"].invoke
143
+ end
137
144
  end
138
145
  end
@@ -1,3 +1,3 @@
1
1
  module Multibase
2
- VERSION = '0.2'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  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.2'
4
+ version: 0.2.1
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-14 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.6.10
160
+ rubygems_version: 2.6.11
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Rails multiple database support