rails_g_database 0.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: 646ab27eeba155e58c6d3daa6a702aeacc5856b7
4
+ data.tar.gz: 91171f61c8c8fd652e66c76694970d36b6458371
5
+ SHA512:
6
+ metadata.gz: bc6fe6ccf9d764f07fa6c944db9c8c073b39e618a00723e8170b3220997fd07ad00e4932952c25ca6300ab148057fc23dc67ab8a3f846bd387d637ab6df2748c
7
+ data.tar.gz: 98bbdb0a1c82a23acbe6365c61af6a629192a0e17c6f60f5a3caf5de6c179298ef9fb19d0d28ddbd9f26ca31d45bda04416a25bb3c93163848a7310d2b41ae85
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails_g_database
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_g_database (0.0.1)
5
+ rails (~> 4.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.1)
11
+ actionpack (= 4.0.1)
12
+ mail (~> 2.5.4)
13
+ actionpack (4.0.1)
14
+ activesupport (= 4.0.1)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.1)
20
+ activesupport (= 4.0.1)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.1)
23
+ activemodel (= 4.0.1)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.1)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.3)
28
+ activesupport (4.0.1)
29
+ i18n (~> 0.6, >= 0.6.4)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ arel (4.0.1)
35
+ atomic (1.1.14)
36
+ builder (3.1.4)
37
+ coderay (1.1.0)
38
+ erubis (2.7.0)
39
+ hike (1.2.3)
40
+ i18n (0.6.5)
41
+ mail (2.5.4)
42
+ mime-types (~> 1.16)
43
+ treetop (~> 1.4.8)
44
+ method_source (0.8.2)
45
+ mime-types (1.25)
46
+ minitest (4.7.5)
47
+ multi_json (1.8.2)
48
+ polyglot (0.3.3)
49
+ pry (0.9.12.3)
50
+ coderay (~> 1.0)
51
+ method_source (~> 0.8)
52
+ slop (~> 3.4)
53
+ rack (1.5.2)
54
+ rack-test (0.6.2)
55
+ rack (>= 1.0)
56
+ rails (4.0.1)
57
+ actionmailer (= 4.0.1)
58
+ actionpack (= 4.0.1)
59
+ activerecord (= 4.0.1)
60
+ activesupport (= 4.0.1)
61
+ bundler (>= 1.3.0, < 2.0)
62
+ railties (= 4.0.1)
63
+ sprockets-rails (~> 2.0.0)
64
+ railties (4.0.1)
65
+ actionpack (= 4.0.1)
66
+ activesupport (= 4.0.1)
67
+ rake (>= 0.8.7)
68
+ thor (>= 0.18.1, < 2.0)
69
+ rake (10.1.0)
70
+ slop (3.4.6)
71
+ sprockets (2.10.0)
72
+ hike (~> 1.2)
73
+ multi_json (~> 1.0)
74
+ rack (~> 1.0)
75
+ tilt (~> 1.1, != 1.3.0)
76
+ sprockets-rails (2.0.1)
77
+ actionpack (>= 3.0)
78
+ activesupport (>= 3.0)
79
+ sprockets (~> 2.8)
80
+ thor (0.18.1)
81
+ thread_safe (0.1.3)
82
+ atomic
83
+ tilt (1.4.1)
84
+ treetop (1.4.15)
85
+ polyglot
86
+ polyglot (>= 0.3.1)
87
+ tzinfo (0.3.38)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bundler (~> 1.3)
94
+ pry
95
+ rails_g_database!
96
+ rake
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrej Antas
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
+ # Rails::G::Database
2
+
3
+ Missing rails database generator (more info comming)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails-g-database'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rails-g-database
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 'Add 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 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generator for setting up another database in Rails
3
+ Just What We were missing
4
+
5
+ Example:
6
+ rails generate database
7
+
8
+ This will create:
9
+ something
@@ -0,0 +1,58 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ class DatabaseGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ argument :attributes, :type => :array, :default => [], :banner => 'field[:adapter]["sqlite|pg|mysql"] field[:db]["database_name"] field[:login]["login"] field[:psswd]["password"] field[:host]["host_name"] field[:port]["port_number"]'
7
+
8
+ check_class_collision
9
+
10
+ def create_config_file
11
+ ["mysql", "pg", "sqlite"].include?(adapter) ? \
12
+ template("#{adapter.to_s}_yml.rb.erb", "config/database_#{file_name}.yml") : \
13
+ raise("Wrong DB adapter chosen, please refer to 'rails g database' for more info")
14
+ end
15
+
16
+ # TODO give these a check, so they wont execute if files already exist
17
+ def create_all_dirs
18
+ system "mkdir db_#{file_name}"
19
+ system "touch db_#{file_name}/.keep"
20
+ system "mkdir db_#{file_name}/migrate"
21
+ system "touch db_#{file_name}/migrate/.keep"
22
+
23
+ system "mkdir app/models/#{file_name}"
24
+ end
25
+
26
+ def create_seeds_file
27
+ template "seeds.rb.erb", "db_#{file_name}/seeds.rb"
28
+ end
29
+
30
+ def create_rake_tasks
31
+ template "rake_task.rb.erb", "lib/tasks/database_#{file_name}.rake"
32
+ end
33
+
34
+ def create_base_model
35
+ template "base_model.rb.erb", "app/models/#{file_name}/base.rb"
36
+ end
37
+
38
+ # TODO write gem for the db into gemfile and run bundle please :)
39
+ # def alter_gemfile
40
+ # end
41
+
42
+ private
43
+ attributes_with_defaults = {
44
+ "adapter" => "sqlite",
45
+ "db" => "",
46
+ "login" => "root",
47
+ "passwd" => "",
48
+ "host" => "localhost",
49
+ "port" => "5432"
50
+ }
51
+
52
+ attributes_with_defaults.each do |method_name, default|
53
+ define_method method_name.to_sym do
54
+ may_be_result = (attributes.find { |a| a.index_name.to_s == method_name.to_s })
55
+ (!may_be_result.nil? || may_be_result.is_a?(Rails::Generators::GeneratedAttribute)) ? may_be_result.type.to_s : default
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ # models/<%= file_name %>/base.rb
2
+
3
+ # Public: Provide a base class for accessing the <%= human_name %> database.
4
+ # All models inheriting from this class will use by default the data <%= human_name %> DB.
5
+ module <%= class_name %>
6
+ class Base < ActiveRecord::Base
7
+
8
+ # Tell Active Record (AR) to not look up for a table called like this class,
9
+ # since this class is only used to add custom config for AR
10
+ self.abstract_class = true
11
+
12
+ databases = YAML::load(IO.read('config/database_<%= file_name %>.yml'))
13
+ establish_connection(databases[Rails.env])
14
+
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # config/database_<%= file_name %>.yml
2
+
3
+ login: &login
4
+ adapter: mysql2
5
+ host: <%= host %>
6
+ username: <%= login %>
7
+ password: <%= passwd %>
8
+
9
+
10
+ development:
11
+ database: <%= db %>_development
12
+ <<: *login
13
+
14
+ test:
15
+ database: <%= db %>_tests
16
+ <<: *login
17
+
18
+ production:
19
+ database: <%= db %>_production
20
+ <<: *login
@@ -0,0 +1,20 @@
1
+ # config/database_<%= file_name %>.yml
2
+
3
+ login: &login
4
+ adapter: postgresql
5
+ host: <%= host %>
6
+ port: <%= port %>
7
+ username: <%= login %>
8
+ password: <%= passwd %>
9
+
10
+ development:
11
+ database: <%= db %>_development
12
+ <<: *login
13
+
14
+ test:
15
+ database: <%= db %>_tests
16
+ <<: *login
17
+
18
+ production:
19
+ database: <%= db %>_production
20
+ <<: *login
@@ -0,0 +1,72 @@
1
+ # lib/tasks/database_<%= file_name %>.rake
2
+
3
+ # Public: This Rake file tries to add what rails provides on the
4
+ # database_<%= %>.rake but for building on top of custom databases.
5
+ # Basically we get the nice db:migrate but for using it on a different DB than
6
+ # the default, by calling it with the namespace defined here.
7
+ #
8
+ # In order to be able to use the default rails rake commands but on a different
9
+ # DB, we are first updating the Rails.application.config.paths and then
10
+ # calling the original rake task. Rails.application.config.paths is getting
11
+ # loaded and available as soon as we call rake since the rakefile in a rails
12
+ # project declares that. Look at Rakefile in the project root for more details.
13
+
14
+
15
+ # Public: Access to the same commands you do for DB operations,
16
+ # like db:drop, db:migrate but using the <%= human_name %> namespace, this will
17
+ # execute on top of the <%= human_name %> DB.
18
+ task :environment
19
+
20
+ namespace :<%= file_name %> do
21
+
22
+ desc "Configure the variables that rails need in order to look up for the db
23
+ configuration in a different folder"
24
+ task :configuration do
25
+ # This is the minimum required to tell rails to use a different location
26
+ # for all the files related to the database.
27
+ ENV['SCHEMA'] = 'db_<%= file_name %>/schema.rb'
28
+ Rails.application.config.paths['db'] = ['db_<%= file_name %>']
29
+ Rails.application.config.paths['db/migrate'] = ['db_<%= file_name %>/migrate']
30
+ Rails.application.config.paths['db/seeds'] = ['db_<%= file_name %>/seeds.rb']
31
+ Rails.application.config.paths['config/database'] = ['config/database_<%= file_name %>.yml']
32
+ end
33
+
34
+ namespace :db do
35
+ task :drop => :configuration do
36
+ Rake::Task["db:drop"].invoke
37
+ end
38
+
39
+ task :create => :configuration do
40
+ Rake::Task["db:create"].invoke
41
+ end
42
+
43
+ task :migrate => :configuration do
44
+ Rake::Task["db:migrate"].invoke
45
+ end
46
+
47
+ task :rollback => :configuration do
48
+ Rake::Task["db:rollback"].invoke
49
+ end
50
+
51
+ task :seed => :configuration do
52
+ Rake::Task["db:seed"].invoke
53
+ end
54
+
55
+ task :version => :configuration do
56
+ Rake::Task["db:version"].invoke
57
+ end
58
+
59
+ task :reset => :configuration do
60
+ Rake::Task['db:drop'].invoke
61
+ Rake::Task['db:create'].invoke
62
+ Rake::Task['db:migrate'].invoke
63
+ end
64
+
65
+
66
+ namespace :test do
67
+ task :prepare => :configuration do
68
+ Rake::Task["db:test:prepare"].invoke
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ # db_<%= file_name %>/seeds.rb
2
+
3
+ ## Put your seed data here
@@ -0,0 +1,16 @@
1
+ # config/database_<%= file_name %>.yml
2
+
3
+ development:
4
+ adapter: sqlite3
5
+ database: db_<%= file_name %>/<%= file_name %>_development.sqlite
6
+ timeout: 5000
7
+
8
+ test:
9
+ adapter: sqlite3
10
+ database: db_<%= file_name %>/<%= file_name %>_test.sqlite
11
+ timeout: 5000
12
+
13
+ production:
14
+ adapter: sqlite3
15
+ database: db_<%= file_name %>/<%= file_name %>_production.sqlite
16
+ timeout: 5000
@@ -0,0 +1,3 @@
1
+ module RailsGDatabase
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "rails_g_database/version"
2
+
3
+ module RailsGDatabase
4
+
5
+ end
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "rails_g_database/version"
4
+
5
+ # Describe your gem and declare its dependencies:
6
+ Gem::Specification.new do |s|
7
+ s.name = "rails_g_database"
8
+ s.version = RailsGDatabase::VERSION
9
+ s.authors = ["redrick"]
10
+ s.email = ["cheaterblue@gmail.com"]
11
+ s.homepage = "https://github.com/redrick/rails-g-database"
12
+ s.summary = "Missing rails database generator and more"
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.required_ruby_version = '>= 1.9.3'
21
+
22
+ s.add_dependency "rails", "~> 4.0.0"
23
+
24
+ s.add_development_dependency "bundler", "~> 1.3"
25
+ s.add_development_dependency "rake"
26
+ s.add_development_dependency "pry"
27
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_g_database
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - redrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-12 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.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.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: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
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: pry
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
+ description:
70
+ email:
71
+ - cheaterblue@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .ruby-gemset
78
+ - .ruby-version
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - MIT-LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/generators/database/USAGE
85
+ - lib/generators/database/database_generator.rb
86
+ - lib/generators/database/templates/base_model.rb.erb
87
+ - lib/generators/database/templates/mysql_yml.rb.erb
88
+ - lib/generators/database/templates/pg_yml.rb.erb
89
+ - lib/generators/database/templates/rake_task.rb.erb
90
+ - lib/generators/database/templates/seeds.rb.erb
91
+ - lib/generators/database/templates/sqlite_yml.rb.erb
92
+ - lib/rails_g_database.rb
93
+ - lib/rails_g_database/version.rb
94
+ - rails_g_database.gemspec
95
+ homepage: https://github.com/redrick/rails-g-database
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: 1.9.3
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.1.5
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Missing rails database generator and more
119
+ test_files: []