banana 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +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
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in banana.gemspec
4
+
5
+ group :development, :test do
6
+ gem 'rake'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 sinsoku
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
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Banana
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'banana'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install banana
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/banana.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/banana/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["sinsoku"]
6
+ gem.email = ["sinsoku.listy@gmail.com"]
7
+ gem.description = %q{}
8
+ gem.summary = %q{}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "banana"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Banana::VERSION
17
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_record'
2
+
3
+ module ActiveRecord
4
+ class Migration
5
+ def migrate_with_multidb(direction)
6
+ if defined? self.class::DATABASE_NAME
7
+ ActiveRecord::Base.establish_connection(self.class::DATABASE_NAME)
8
+ migrate_without_multidb(direction)
9
+ ActiveRecord::Base.establish_connection(Rails.env)
10
+ else
11
+ migrate_without_multidb(direction)
12
+ end
13
+ end
14
+ alias_method_chain :migrate, :multidb
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_record'
2
+
3
+ module Banana
4
+ class MultidbSchemaDumper < ActiveRecord::SchemaDumper
5
+ public :header, :tables, :trailer
6
+
7
+ def self.dump_multidb(specs=[], stream=STDOUT)
8
+ specs.each_with_index do |spec, index|
9
+ ActiveRecord::Base.establish_connection(spec)
10
+ dumper = new(ActiveRecord::Base.connection)
11
+ dumper.header(stream) if index == 0
12
+ dumper.tables(stream)
13
+ dumper.trailer(stream) if index == specs.count - 1
14
+ end
15
+ stream
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ tasks = Rake.application.instance_variable_get '@tasks'
2
+ tasks.delete 'db:create'
3
+ tasks.delete 'db:drop'
4
+ tasks.delete 'db:schema:dump'
5
+
6
+ db_namespace = namespace :db do
7
+ desc 'Create the multiple databases from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
8
+ task :create => :load_config do
9
+ configs_for_multi_environment.each { |config| create_database(config) }
10
+ end
11
+
12
+ desc 'Drops the multiple databases for the current Rails.env (use db:drop:all to drop all databases)'
13
+ task :drop => :load_config do
14
+ configs_for_multi_environment.each { |config| drop_database_and_rescue(config) }
15
+ end
16
+
17
+ namespace :schema do
18
+ desc 'Create a db/schema.rb file that can be portably used against any DB supported by AR'
19
+ task :dump => [:environment, :load_config] do
20
+ require 'banana/multidb_schema_dumper'
21
+ filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
22
+ File.open(filename, "w:utf-8") do |file|
23
+ environments = ActiveRecord::Base.configurations.keys.select { |x| x =~ /#{Rails.env}$/ }
24
+ Banana::MultidbSchemaDumper.dump_multidb(environments, file)
25
+ end
26
+ db_namespace['schema:dump'].reenable
27
+ end
28
+ end
29
+ end
30
+
31
+ def configs_for_multi_environment
32
+ environments = ActiveRecord::Base.configurations.keys.select { |x| x =~ /#{Rails.env}$/ }
33
+ environments += ActiveRecord::Base.configurations.keys.select { |x| x =~ /test$/ } if Rails.env.development?
34
+ ActiveRecord::Base.configurations.values_at(*environments).compact.reject { |config| config['database'].blank? }
35
+ end
@@ -0,0 +1,3 @@
1
+ module Banana
2
+ VERSION = "0.0.1"
3
+ end
data/lib/banana.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "banana/version"
2
+
3
+ module Banana
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "banana/tasks/database.rake"
7
+ end
8
+ end
9
+ end
10
+
11
+ require "banana/migration"
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banana
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sinsoku
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ''
15
+ email:
16
+ - sinsoku.listy@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - banana.gemspec
27
+ - lib/banana.rb
28
+ - lib/banana/migration.rb
29
+ - lib/banana/multidb_schema_dumper.rb
30
+ - lib/banana/tasks/database.rake
31
+ - lib/banana/version.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ segments:
45
+ - 0
46
+ hash: 794066873675753290
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ segments:
54
+ - 0
55
+ hash: 794066873675753290
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: ''
62
+ test_files: []