multi_config 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,4 +16,5 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
- .rbenv*
19
+ .rbenv-version
20
+ .rvm*
@@ -0,0 +1,27 @@
1
+ Unreleased ([changes](https://github.com/shadabahmed/multi_config/v0.1.6...master))
2
+ -------------------
3
+ **Note: Not implemented yet**
4
+
5
+ * Further refactoring
6
+ * Add generators for migration
7
+
8
+ v0.1.6, 2012-09-09 ([changes](https://github.com/shadabahmed/multi_config/compare/v0.1.1...v0.1.6))
9
+ -------------------
10
+ * Further refactoring
11
+ * Tons of documentation
12
+ * More test cases
13
+ * Removed some methods into a module to prevent polluting ActiveRecord
14
+
15
+ v0.1.1, 2012-09-09 ([changes](https://github.com/shadabahmed/multi_config/compare/v0.1.0...v0.1.1))
16
+ -------------------
17
+ * Build breaking because of a missing folder fixed
18
+
19
+ v0.1.0, 2012-09-09 ([changes](https://github.com/shadabahmed/multi_config/compare/v0.0.1...v0.1.0))
20
+ -------------------
21
+ * Refactored quite a bit
22
+ * 100% coverage for majority of the gem, except the railtie class.
23
+
24
+ v0.0.1, 2012-09-08 ([source](https://github.com/shadabahmed/multi_config/tree/53bf0b63f8e217379459b83b173c319039d6edc0))
25
+ -------------------
26
+ * First commit with working code
27
+ * Good test coverage
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
  group :test do
7
7
  gem 'rake'
8
8
  gem 'rspec'
9
- gem 'autotest'
9
+ gem 'autotest', :require => false
10
10
  gem 'simplecov', :platforms => :mri_19, :require => false
11
11
  gem 'rcov', :platforms => :mri_18
12
12
  gem 'rails', '~> 3.0'
data/README.md CHANGED
@@ -1,37 +1,69 @@
1
- # ActiveRecordMultiConfig
1
+ # MultiConfig [![Build Status](https://secure.travis-ci.org/shadabahmed/multi_config.png)](https://secure.travis-ci.org/shadabahmed/multi_config)
2
2
 
3
- ## Build Status
4
- [![Build Status](https://secure.travis-ci.org/shadabahmed/multi_config.png)](https://secure.travis-ci.org/shadabahmed/multi_config)
3
+ ## Description
5
4
 
6
- TODO: Write a gem description
5
+ This `acts_as` style extension provides the capabilities for using multiple database configuration files. Any model can
6
+ specify what database config file to use by using a Rails 3.2 style self.config_file= method.
7
7
 
8
8
  ## Installation
9
9
 
10
- Add this line to your application's Gemfile:
10
+ In your Gemfile:
11
11
 
12
12
  gem 'multi_config'
13
13
 
14
- And then execute:
14
+ Or, from the command line:
15
15
 
16
- $ bundle
16
+ gem install multi_config
17
17
 
18
- Or install it yourself as:
18
+ ## Example
19
19
 
20
- $ gem install multi_config
20
+ class DifferentTable < ActiveRecord::Base
21
+ self.config_file = 'other_db'
22
+ end
21
23
 
22
- ## Usage
24
+ # In config/other_db.yml
23
25
 
24
- This gem will allow multiple db config files to be used in a Rails 3 project. All you have to do is
25
- ```ruby
26
- class MyTable < ActiveRecord::Base
27
- self.config_file = 'my_config'
28
- end
29
- ```
26
+ development: &development
27
+ database: db/other_db
28
+ host: localhost
29
+ adapter: sqlite3
30
30
 
31
- ## Contributing
31
+ test:
32
+ <<: *development
32
33
 
33
- 1. Fork it
34
- 2. Create your feature branch (`git checkout -b my-new-feature`)
35
- 3. Commit your changes (`git commit -am 'Add some feature'`)
36
- 4. Push to the branch (`git push origin my-new-feature`)
37
- 5. Create new Pull Request
34
+
35
+ ## Notes
36
+ All database config files should be similar to the database.yml. You need to specify configuration for all the environments
37
+ in use like you would specify in database.yml.
38
+
39
+ ActiveRecord uses *ActiveRecord::Base.configurations* hash to store configurations. This extension modifies the *configurations*
40
+ hash by adding the configurations from the other database files. The keys for the configuration in the other config are namespaced.
41
+ For e.g. if you specify `other_db` config file with environments `test` and `development` then configurations hash would have
42
+ these configs in `other_db_test` and `other_db_development` keys.
43
+
44
+ If you need to create migrations for the other db, then you will have to make modifications in the migration file. See this
45
+ [guide](http://stackoverflow.com/questions/1404620/using-rails-migration-on-different-database-than-standard-production-or-devel) on
46
+ how to do that. The parameter for `establish_connection` would be the namespaced key for you config.
47
+
48
+
49
+ ## Versions
50
+ All versions require Rails 3.0.x and higher.
51
+
52
+ ## Roadmap
53
+
54
+ 1. Add support for generators where you can specify which db file to use in the rails generate command. Would mitigate the need to manually modify migrations.
55
+ 2. Support for Rails 4
56
+
57
+ ## Contributing to `multi_config`
58
+
59
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
60
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
61
+ - Fork the project
62
+ - Start a feature/bugfix branch
63
+ - Commit and push until you are happy with your contribution
64
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
65
+ - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
66
+
67
+ ## Copyright
68
+
69
+ Copyright (c) 2012 Shadab Ahmed, released under the MIT license
data/Rakefile CHANGED
@@ -1,12 +1,15 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
- require 'fileutils'
3
+
4
+ # Add default task. When you type just rake command this would run. Travis CI runs this. Making this run spec
4
5
  desc 'Default: run specs.'
5
6
  task :default => :spec
6
7
 
8
+ # Defining spec task for running spec
7
9
  desc "Run specs"
8
- RSpec::Core::RakeTask.new('spec') do |t|
9
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
10
+ RSpec::Core::RakeTask.new('spec') do |spec|
11
+ # Pattern filr for spec files to run. This is default btw.
12
+ spec.pattern = "./spec/**/*_spec.rb"
10
13
  end
11
14
 
12
15
  # Run the rdoc task to generate rdocs for this gem
@@ -21,23 +24,19 @@ RDoc::Task.new do |rdoc|
21
24
  rdoc.rdoc_files.include('lib/**/*.rb')
22
25
  end
23
26
 
27
+ # Code coverage tasks. Different for Ruby 1.8 vs 1.9
24
28
  if RUBY_VERSION =~ /^1\.8/
25
- RSpec::Core::RakeTask.new(:rcov) do |spec|
26
- spec.pattern = 'spec/**/*_spec.rb'
27
- spec.rcov = true
28
- spec.rcov_opts = %w{--exclude pkg\/,spec\/,features\/}
29
- end
30
- else
31
- desc "Code coverage detail"
32
- task :simplecov do
33
- ENV['COVERAGE'] = "true"
34
- Rake::Task['spec'].execute
35
- end
36
- end
37
-
38
-
39
- desc "Run all specs with rcov"
40
- RSpec::Core::RakeTask.new(:rcov) do |t|
41
- t.rcov = true
42
- t.rcov_opts = %w{--exclude pkg\/,spec\/,features\/}
29
+ # Ruby 1.8 uses rcov for code coverage
30
+ RSpec::Core::RakeTask.new(:coverage) do |spec|
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ spec.rcov_opts = %w{--exclude pkg\/,spec\/,features\/}
34
+ end
35
+ else
36
+ # Ruby 1.9+ using simplecov. Note: Simplecov config defined in spec_helper
37
+ desc "Code coverage detail"
38
+ task :coverage do
39
+ ENV['COVERAGE'] = "true"
40
+ Rake::Task['spec'].execute
41
+ end
43
42
  end
@@ -1,21 +1,29 @@
1
1
  require "multi_config/version"
2
2
 
3
+ # Module for this gem
3
4
  module MultiConfig
5
+ # Checking if Rails::Railtie exists. Only then loca this railtie
4
6
  if defined? Rails::Railtie
5
7
  require 'rails'
6
8
  class Railtie < Rails::Railtie
9
+ # Railtie initializer method
7
10
  initializer 'multi_config.active_record' do
11
+ # When active_record is loaded, only then run this. See method documentation to learn mode
8
12
  ActiveSupport.on_load :active_record do
9
- MultiConfig::Railtie.insert
13
+ # Notice that full namespace is not given since search for Railtie class begin from this Module itself.
14
+ Railtie.insert
10
15
  end
11
16
  end
12
17
  end
13
18
  end
14
19
 
15
20
  class Railtie
21
+ # Include the module MultiConfig::ORMs::ActiveRecord in ActiveRecord::Base class
16
22
  def self.insert
23
+ # Even though ActiveSupport called this method only when ActiveRecord was loaded. We are just being extra safe.
17
24
  if defined?(ActiveRecord)
18
25
  require 'multi_config/orms/active_record'
26
+ # Calling private method :include via send. This is typically used in extensions to include a module.
19
27
  ActiveRecord::Base.send(:include, MultiConfig::ORMs::ActiveRecord)
20
28
  end
21
29
  end
@@ -1,37 +1,80 @@
1
1
  module MultiConfig
2
+ # This module encloses implementations for multiple ORMs
2
3
  module ORMs
4
+ # Implementation for the ActiveRecord ORM
3
5
  module ActiveRecord
4
6
  def self.included(mod)
5
7
  mod.extend ClassMethods
8
+ # Setting @@db_configs in the including class. This will help us keep track of database configuration files already included
6
9
  mod.send(:class_variable_set, :'@@db_configs', Hash.new { |h, k| h[k] = [] })
7
10
  end
8
11
 
12
+ # This `acts_as` style extension provides the capabilities for using multiple database configuration files. Any
13
+ # model can specify what database config file to use by using a Rails 3.2 style self.config_file= method.
14
+ #
15
+ # Example:
16
+ #
17
+ # class DifferentTable < ActiveRecord::Base
18
+ # self.config_file = 'other_db'
19
+ # end
20
+ #
21
+ # In config/other_db.yml
22
+ #
23
+ # development: &development
24
+ # database: db/other_db
25
+ # host: localhost
26
+ # adapter: sqlite3
27
+ #
28
+ # test:
29
+ # <<: *development
9
30
  module ClassMethods
31
+ # Use the specified config file for database. You can specify file without .yml extension. If you specify database.yml or
32
+ # database, it will not have any effect since that is loaded by default.
10
33
  def config_file=(file_name)
11
34
  file_name += '.yml' unless File.extname(file_name).eql? '.yml'
35
+ # Load config file if it is not database.yml
12
36
  unless file_name == 'database.yml'
13
37
  namespace = File.basename(file_name, '.yml')
38
+ # Update active_record configurations hash
14
39
  add_db_config(file_name, namespace)
40
+ # Raise error if the config file does not have the current environment
15
41
  raise "Configuration for #{::Rails.env} environment not defined in #{Config.path file_name}" unless configurations.include? "#{namespace}_#{::Rails.env}"
42
+ # Establish connection. This is the only way I found to different database config. Will try to find alternative
16
43
  establish_connection "#{namespace}_#{::Rails.env}"
17
44
  end
18
45
  end
19
46
 
20
47
  private
48
+ # Adds namespaced database configuration to configurations hash.
49
+ # * +file_name+ - file name of the database config file
50
+ # * +namespace+ - this is the basename of the file. e.g. other_db when file is other_db.yml. Any other can be specified
51
+ # If a db config file has been added to the configurations once with a specific namespace, it will not be loaded again for
52
+ # same namespace. For .e.g. Models A and B specify config file 'other_db', then other_db.yml will be read only once.
21
53
  def add_db_config(file_name, namespace)
54
+ # Read class var from the including class
22
55
  db_configs = class_variable_get(:'@@db_configs')
56
+
57
+ # Don't do anything if the namespace has already been added
23
58
  unless db_configs.include?(namespace)
24
59
  configurations.merge!(Config.load(file_name, namespace))
60
+ # Add class name in db_configs. This is to keep track of models that have specified a particular db config file.
25
61
  db_configs[namespace] << name
26
62
  end
27
63
  end
28
64
  end
29
65
 
66
+ # Defines helper methods to be used the the extension. Since this is in the enclosing module for ClassMethods Module.
67
+ # This will be searched first when Config is referenced. The Ruby Programming Language - Page 276
30
68
  module Config
69
+
70
+ # Returns the absolute path for the file specified. The file is supposed to be located in the config folder.
31
71
  def self.path(file_name)
32
72
  File.join(Rails.root, 'config', file_name)
33
73
  end
34
74
 
75
+ # Load a yaml file and modify the keys by appending <tt><namespace>_</tt> string in the keys. For e.g. if a yaml
76
+ # file with namespace other_db is loaded with environments test and development, the returned hash from this method
77
+ # would contain keys 'other_db_test' and 'other_db_development'.
35
78
  def self.load(file_name, namespace)
36
79
  begin
37
80
  require 'erb'
@@ -1,3 +1,4 @@
1
1
  module MultiConfig
2
- VERSION = "0.1.1"
2
+ # Gem version
3
+ VERSION = "0.1.6"
3
4
  end
@@ -1,5 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # This is a good way to get paths relative to current file.
2
3
  lib = File.expand_path('../lib', __FILE__)
4
+ # Explicitly add to load path. Notice this is adding in the beginning so that our file is found first
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'multi_config/version'
5
7
 
@@ -12,13 +14,16 @@ Gem::Specification.new do |gem|
12
14
  gem.summary = %q{Use this gem to use multiple db config files}
13
15
  gem.homepage = "https://github.com/shadabahmed/multi_config"
14
16
 
15
- # Load Paths...
17
+ # Load Paths. Git gives a good way to specify files while building the gem without having to put the whole list in here
16
18
  gem.files = `git ls-files`.split($/)
17
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
21
  gem.require_paths = ["lib"]
20
22
 
21
- # Dependencies (installed via 'bundle install')...
23
+ # Added dependencies for runtime
24
+ gem.add_runtime_dependency "rails", [">= 3.0"]
25
+
26
+ # Added dependencies for development/test
22
27
  gem.add_development_dependency("bundler", [">= 1.0.0"])
23
28
  gem.add_development_dependency("rails", [">= 3.0"])
24
29
  gem.add_development_dependency("activerecord", [">= 3.0"])
@@ -1,103 +1,123 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe MultiConfig::ORMs::ActiveRecord do
4
- let!(:db_config){ load_namespaced_config('database.yml') }
5
- let!(:other_config){ load_namespaced_config('other.yml') }
6
- before(:each) do
7
- @test_class = Class.new
8
- @test_class.stub_chain(:name).and_return('test_class')
9
- @test_class.stub(:configurations).and_return({})
10
- @test_class.stub(:establish_connection)
11
- @test_class.send(:include, MultiConfig::ORMs::ActiveRecord)
12
- end
13
- let(:test_class){@test_class}
14
-
15
- describe "#config_file=" do
4
+ let!(:db_config) { load_namespaced_config('database.yml') }
5
+ let!(:other_config) { load_namespaced_config('other.yml') }
6
+ let!(:erb_config) { load_namespaced_config('erb.yml') }
16
7
 
17
- it "should raise an error if file is not in present" do
18
- lambda{test_class.config_file = 'none'}.should raise_error
8
+ describe MultiConfig::ORMs::ActiveRecord::ClassMethods do
9
+ before(:each) do
10
+ @test_class = Class.new
11
+ @test_class.stub_chain(:name).and_return('test_class')
12
+ @test_class.stub(:configurations).and_return({})
13
+ @test_class.stub(:establish_connection)
14
+ @test_class.send(:include, MultiConfig::ORMs::ActiveRecord)
19
15
  end
16
+ let(:test_class) { @test_class }
20
17
 
21
- describe "should raise error in unspecified environment" do
22
- before do
23
- Rails.stub(:env).and_return('unknown')
24
- end
25
- it "should through error when I specify a config file with environment not defined" do
26
- lambda{test_class.config_file = 'other'}.should raise_error
18
+ describe "#config_file=" do
19
+
20
+ it "should raise an error if file is not in present" do
21
+ lambda { test_class.config_file = 'none' }.should raise_error
27
22
  end
28
- end
29
23
 
30
- it "should through error when I specify invalid config file" do
31
- lambda{test_class.config_file = 'invalid'}.should raise_error
32
- end
24
+ describe "should raise error in unspecified environment" do
25
+ before do
26
+ Rails.stub(:env).and_return('unknown')
27
+ end
28
+ it "should through error when I specify a config file with environment not defined" do
29
+ lambda { test_class.config_file = 'other' }.should raise_error
30
+ end
31
+ end
33
32
 
34
- describe "should modify class variable @@db_configs" do
35
- before do
36
- test_class.send(:class_variable_get, '@@db_configs').should == {}
37
- test_class.config_file = 'other'
33
+ it "should through error when I specify invalid config file" do
34
+ lambda { test_class.config_file = 'invalid' }.should raise_error
38
35
  end
39
- subject {test_class.send(:class_variable_get, '@@db_configs')}
40
- it{should == {"other" => ["test_class"]}}
41
- end
42
36
 
43
- describe "should modify .configurations" do
44
- before do
45
- test_class.should_receive(:establish_connection).once.with('other_test')
46
- expect {
37
+ describe "should modify class variable @@db_configs" do
38
+ before do
39
+ test_class.send(:class_variable_get, '@@db_configs').should == {}
47
40
  test_class.config_file = 'other'
48
- }.to change(test_class, :configurations).from({}).to(other_config)
41
+ end
42
+ subject { test_class.send(:class_variable_get, '@@db_configs') }
43
+ it { should == {"other" => ["test_class"]} }
49
44
  end
50
- subject {test_class.configurations}
51
- it{should include 'other_development'}
52
- it{should include 'other_test'}
53
- end
54
45
 
55
- describe "should work as expected when filename with extension .yml is specified" do
56
- before do
57
- test_class.should_receive(:establish_connection).once.with('other_test')
58
- expect {
59
- test_class.config_file = 'other.yml'
60
- }.to change(test_class, :configurations).from({}).to(other_config)
46
+ describe "should modify .configurations" do
47
+ before do
48
+ test_class.should_receive(:establish_connection).once.with('other_test')
49
+ expect {
50
+ test_class.config_file = 'other'
51
+ }.to change(test_class, :configurations).from({}).to(other_config)
52
+ end
53
+ subject { test_class.configurations }
54
+ it { should include 'other_development' }
55
+ it { should include 'other_test' }
61
56
  end
62
- subject {test_class.configurations.keys}
63
- it{should include 'other_development'}
64
- it{should include 'other_test'}
65
- end
66
57
 
67
- describe "multiple calls for config_file= in different models should modify configurations only once" do
68
- let(:first_test_class) {Class.new(test_class)}
69
- let(:second_test_class) {Class.new(test_class)}
70
- before do
71
- first_test_class.should_receive(:establish_connection).once.with('other_test')
72
- expect {
73
- first_test_class.config_file = 'other.yml'
74
- }.to change(test_class, :configurations).from({}).to(other_config)
58
+ describe "should work as expected when filename with extension .yml is specified" do
59
+ before do
60
+ test_class.should_receive(:establish_connection).once.with('other_test')
61
+ expect {
62
+ test_class.config_file = 'other.yml'
63
+ }.to change(test_class, :configurations).from({}).to(other_config)
64
+ end
65
+ subject { test_class.configurations.keys }
66
+ it { should include 'other_development' }
67
+ it { should include 'other_test' }
68
+ end
69
+
70
+ describe "multiple calls for config_file= in different models should modify configurations only once" do
71
+ let(:first_test_class) { Class.new(test_class) }
72
+ let(:second_test_class) { Class.new(test_class) }
73
+ before do
74
+ first_test_class.should_receive(:establish_connection).once.with('other_test')
75
+ expect {
76
+ first_test_class.config_file = 'other.yml'
77
+ }.to change(test_class, :configurations).from({}).to(other_config)
75
78
 
76
- second_test_class.should_receive(:establish_connection).once.with('other_test')
77
- expect {
78
- second_test_class.config_file = 'other'
79
- }.not_to change(test_class, :configurations)
79
+ second_test_class.should_receive(:establish_connection).once.with('other_test')
80
+ expect {
81
+ second_test_class.config_file = 'other'
82
+ }.not_to change(test_class, :configurations)
80
83
 
84
+ end
85
+ subject { second_test_class.configurations.keys }
86
+ it { should include 'other_development' }
87
+ it { should include 'other_test' }
88
+ end
89
+
90
+ describe "should not do anything if database.yml specified" do
91
+ before do
92
+ test_class.should_not_receive(:establish_connection)
93
+ test_class.should_not_receive(:add_db_config)
94
+ MultiConfig::ORMs::ActiveRecord::Config.should_not_receive(:path)
95
+ MultiConfig::ORMs::ActiveRecord::Config.should_not_receive(:load)
96
+ expect {
97
+ test_class.config_file = 'database'
98
+ }.not_to change(test_class, :configurations)
99
+ end
100
+ subject { test_class.configurations.keys }
101
+ it { should_not include 'database_development' }
102
+ it { should_not include 'database_test' }
81
103
  end
82
- subject {second_test_class.configurations.keys}
83
- it{should include 'other_development'}
84
- it{should include 'other_test'}
85
104
  end
105
+ end
86
106
 
87
- describe "should not do anything if database.yml specified" do
107
+ describe MultiConfig::ORMs::ActiveRecord::Config do
108
+ describe '#path' do
88
109
  before do
89
- test_class.should_not_receive(:establish_connection)
90
- test_class.should_not_receive(:add_db_config)
91
- MultiConfig::ORMs::ActiveRecord::Config.should_not_receive(:path)
92
- MultiConfig::ORMs::ActiveRecord::Config.should_not_receive(:load)
93
- expect {
94
- test_class.config_file = 'database'
95
- }.not_to change(test_class, :configurations)
110
+ Rails.stub(:root).and_return('/')
96
111
  end
97
- subject {test_class.configurations.keys}
98
- it{should_not include 'database_development'}
99
- it{should_not include 'database_test'}
112
+ subject { MultiConfig::ORMs::ActiveRecord::Config.path('other_db.yml') }
113
+ it { should == '/config/other_db.yml' }
100
114
  end
101
115
 
116
+ describe '#load' do
117
+ it "should load yaml and erb/yaml files correctly" do
118
+ MultiConfig::ORMs::ActiveRecord::Config.load('other.yml','other').should == other_config
119
+ MultiConfig::ORMs::ActiveRecord::Config.load('erb.yml','erb').should == erb_config
120
+ end
121
+ end
102
122
  end
103
123
  end
@@ -1,23 +1,40 @@
1
+ # Notice there is a .rspec file in the root folder. It defines rspec arguments
2
+
3
+ # Ruby 1.9 uses simplecov. The ENV['COVERAGE'] is set when rake coverage is run in ruby 1.9
1
4
  if ENV['COVERAGE']
2
5
  require 'simplecov'
3
6
  SimpleCov.start do
7
+ # Remove the spec folder from coverage. By default all code files are included. For more config options see
8
+ # https://github.com/colszowka/simplecov
4
9
  add_filter File.expand_path('../../spec',__FILE__)
5
10
  end
6
11
  end
12
+
13
+ # Modify load path so you can require 'multi_config' directly.
7
14
  $LOAD_PATH.unshift(File.expand_path('../../lib',__FILE__))
8
15
 
9
16
  require 'rubygems'
17
+ # Loads bundler setup tasks. Now if I run spec without installing gems then it would say gem not installed and
18
+ # do bundle install instead of ugly load error on require.
10
19
  require 'bundler/setup'
20
+
21
+ # This will require me all the gems automatically for the groups. If I do only .setup then I will have to require gems
22
+ # manually. Note that you have still have to require some gems if they are part of bigger gem like ActiveRecord which is
23
+ # part of Rails. You can say :require => false in gemfile to always use explicit requiring
11
24
  Bundler.require(:default, :test)
12
25
  require 'active_record'
13
26
 
14
27
  require 'multi_config/orms/active_record'
28
+ # This is required to rcov to run. Otherwise it runs without specs
15
29
  require 'rspec/autorun'
16
30
 
17
31
  # Requires supporting ruby files with custom matchers and macros, etc,
18
32
  # in spec/support/ and its subdirectories.
19
33
  Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
20
34
 
35
+ # Set Rails environment as test
36
+ ENV['RAILS_ENV'] = 'test'
37
+
21
38
  # This file was generated by the `rspec --init` command. Conventionally, all
22
39
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
23
40
  # Require this file using `require "spec_helper"` to ensure that it is only
@@ -33,6 +50,8 @@ RSpec.configure do |config|
33
50
  # the seed, which is printed after each run.
34
51
  # --seed 1234
35
52
  config.order = 'random'
53
+
54
+ # Setting rails default settings such as Rails.root before every spec
36
55
  config.before(:each) do
37
56
  set_rails_conf
38
57
  end
@@ -1,3 +1,4 @@
1
+ # Setting default Active Record configs
1
2
  ActiveRecord::Base.logger = Logger.new(StringIO.new)
2
3
  ActiveRecord::Base.configurations = YAML.load_file(ERB.new(File.expand_path("../config/database.yml",__FILE__)).result)
3
4
 
@@ -1,6 +1,5 @@
1
1
  development: &development
2
2
  database: db/db
3
- host: localhost
4
3
  adapter: sqlite3
5
4
 
6
5
  test:
@@ -0,0 +1,4 @@
1
+ development: &development
2
+ database: <%= 'erb_db' %>
3
+ adapter: <%= 'sqlite3' %>
4
+
@@ -1,3 +1,3 @@
1
- #Do not change this. It contains binary data
1
+ #Do not change this. It contains binary data for invalid yml
2
2
  :
3
3
  
@@ -1,6 +1,5 @@
1
1
  development: &development
2
2
  database: db/other_db
3
- host: localhost
4
3
  adapter: sqlite3
5
4
 
6
5
  test:
@@ -1,3 +1,4 @@
1
+ # Loads a namespaced config. Similar to the load method in MultiConfig::ORMs::ActiveRecord::Config.path method
1
2
  def load_namespaced_config(file)
2
3
  namespace = File.basename(file, File.extname(file))
3
4
  config = YAML.load(ERB.new(IO.read(File.expand_path("../config/#{file}", __FILE__))).result)
@@ -1,4 +1,4 @@
1
+ # Stub out rails root method.
1
2
  def set_rails_conf
2
- Rails.stub(:env).and_return('test')
3
3
  Rails.stub(:root).and_return(File.expand_path('../', __FILE__))
4
4
  end
metadata CHANGED
@@ -1,124 +1,139 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: multi_config
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Shadab Ahmed
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-09 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: bundler
12
+ date: 2012-09-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
24
25
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 23
29
- segments:
30
- - 1
31
- - 0
32
- - 0
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
33
37
  version: 1.0.0
34
38
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rails
38
39
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
40
41
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 3
47
- - 0
48
- version: "3.0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
49
54
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: activerecord
53
55
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activerecord
64
+ requirement: !ruby/object:Gem::Requirement
55
65
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 7
60
- segments:
61
- - 3
62
- - 0
63
- version: "3.0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
64
70
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: autotest
68
71
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: autotest
80
+ requirement: !ruby/object:Gem::Requirement
70
81
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 27
75
- segments:
76
- - 4
77
- - 0
78
- version: "4.0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '4.0'
79
86
  type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: rdoc
83
87
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '4.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rdoc
96
+ requirement: !ruby/object:Gem::Requirement
85
97
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
93
102
  type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- name: sqlite3
97
103
  prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sqlite3
112
+ requirement: !ruby/object:Gem::Requirement
99
113
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
107
118
  type: :development
108
- version_requirements: *id006
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
109
126
  description: This gem lets you specify different config file for an ActiveRecord Model
110
- email:
111
- - ""
127
+ email:
128
+ - ''
112
129
  executables: []
113
-
114
130
  extensions: []
115
-
116
131
  extra_rdoc_files: []
117
-
118
- files:
132
+ files:
119
133
  - .gitignore
120
134
  - .rspec
121
135
  - .travis.yml
136
+ - CHANGELOG.md
122
137
  - Gemfile
123
138
  - LICENSE.txt
124
139
  - README.md
@@ -134,6 +149,7 @@ files:
134
149
  - spec/spec_helper.rb
135
150
  - spec/support/active_record_config.rb
136
151
  - spec/support/config/database.yml
152
+ - spec/support/config/erb.yml
137
153
  - spec/support/config/invalid.yml
138
154
  - spec/support/config/other.yml
139
155
  - spec/support/config_helper.rb
@@ -142,38 +158,29 @@ files:
142
158
  - spec/support/rails_config.rb
143
159
  homepage: https://github.com/shadabahmed/multi_config
144
160
  licenses: []
145
-
146
161
  post_install_message:
147
162
  rdoc_options: []
148
-
149
- require_paths:
163
+ require_paths:
150
164
  - lib
151
- required_ruby_version: !ruby/object:Gem::Requirement
165
+ required_ruby_version: !ruby/object:Gem::Requirement
152
166
  none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- hash: 3
157
- segments:
158
- - 0
159
- version: "0"
160
- required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
172
  none: false
162
- requirements:
163
- - - ">="
164
- - !ruby/object:Gem::Version
165
- hash: 3
166
- segments:
167
- - 0
168
- version: "0"
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
169
177
  requirements: []
170
-
171
178
  rubyforge_project:
172
- rubygems_version: 1.8.24
179
+ rubygems_version: 1.8.23
173
180
  signing_key:
174
181
  specification_version: 3
175
182
  summary: Use this gem to use multiple db config files
176
- test_files:
183
+ test_files:
177
184
  - spec/active_record_spec.rb
178
185
  - spec/models/uses_database_yml_spec.rb
179
186
  - spec/models/uses_other_yml_spec.rb
@@ -181,6 +188,7 @@ test_files:
181
188
  - spec/spec_helper.rb
182
189
  - spec/support/active_record_config.rb
183
190
  - spec/support/config/database.yml
191
+ - spec/support/config/erb.yml
184
192
  - spec/support/config/invalid.yml
185
193
  - spec/support/config/other.yml
186
194
  - spec/support/config_helper.rb