create-rails-dev-db 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brian Burridge
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = create-rails-dev-db
2
+
3
+ This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Brian Burridge. See LICENSE for details.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "create-rails-dev-db"
8
+ gem.summary = %Q{This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.}
9
+ gem.description = %Q{This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.}
10
+ gem.email = "bburridg@gmail.com"
11
+ gem.homepage = "http://github.com/bburridge/create-rails-dev-db"
12
+ gem.authors = ["Brian Burridge"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.files << "config/database.yml"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "create-rails-dev-db #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'create-rails-dev-db'
4
+
5
+ exit CreateRailsDevDB::Application.run!(*ARGV)
@@ -0,0 +1,47 @@
1
+ # MySQL. Versions 4.1 and 5.0 are recommended.
2
+ #
3
+ # Install the MySQL driver:
4
+ # gem install mysql
5
+ # On Mac OS X:
6
+ # sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
7
+ # On Mac OS X Leopard:
8
+ # sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
9
+ # This sets the ARCHFLAGS environment variable to your native architecture
10
+ # On Windows:
11
+ # gem install mysql
12
+ # Choose the win32 build.
13
+ # Install MySQL and put its /bin directory on your path.
14
+ #
15
+ # And be sure to use new-style password hashing:
16
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
17
+ development:
18
+ adapter: mysql
19
+ encoding: utf8
20
+ reconnect: false
21
+ database: $dbname
22
+ pool: 5
23
+ username: $username
24
+ password: $password
25
+
26
+ # Warning: The database defined as "test" will be erased and
27
+ # re-generated from your development database when you run "rake".
28
+ # Do not set this db to the same as development or production.
29
+ test:
30
+ adapter: mysql
31
+ encoding: utf8
32
+ reconnect: false
33
+ database: $dbname_test
34
+ pool: 5
35
+ username:
36
+ password:
37
+ socket: /tmp/mysql.sock
38
+
39
+ production:
40
+ adapter: mysql
41
+ encoding: utf8
42
+ reconnect: false
43
+ database: $dbname_prod
44
+ pool: 5
45
+ username:
46
+ password:
47
+ socket: /tmp/mysql.sock
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{create-rails-dev-db}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brian Burridge"]
12
+ s.date = %q{2010-08-30}
13
+ s.default_executable = %q{create-rails-dev-db}
14
+ s.description = %q{This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.}
15
+ s.email = %q{bburridg@gmail.com}
16
+ s.executables = ["create-rails-dev-db"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/create-rails-dev-db",
29
+ "config/database.yml",
30
+ "create-rails-dev-db.gemspec",
31
+ "lib/create-rails-dev-db.rb",
32
+ "test/helper.rb",
33
+ "test/test_create-rails-dev-db.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/bburridge/create-rails-dev-db}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_create-rails-dev-db.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ end
57
+ end
58
+
@@ -0,0 +1,65 @@
1
+ module CreateRailsDevDB
2
+ class Application
3
+ class << self
4
+ def run!(*arguments)
5
+ current_app_name = Dir.pwd.split("/").last
6
+
7
+ # Ask for database name, defaulting to current directory name (presuming it is being run within the rails app folder)
8
+ puts "Database name [#{current_app_name[0..64]}_development]: "
9
+ dbname_entry = gets.chomp
10
+ while dbname_entry.size > (64-12)
11
+ puts "*Name of db is too long (#{dbname_entry.size}. The limit is 64.)"
12
+ dbname_entry = gets.chomp
13
+ end
14
+
15
+ if dbname_entry.nil? || dbname_entry.size == 0
16
+ dbname = current_app_name[0..64]
17
+ dbname = "#{dbname}_development"
18
+ else
19
+ dbname = dbname_entry
20
+ end
21
+
22
+ # Name dbs of other environment
23
+ dbname_prod = "#{dbname}_production"
24
+ dbname_test = "#{dbname}_test"
25
+
26
+
27
+ # Ask for username for db to be created, defaulting to app name plus _dev
28
+ puts "Username [#{current_app_name}_dev]: "
29
+ username = gets.chomp
30
+ username = "#{current_app_name}_dev" if username.nil? || username.size == 0
31
+
32
+ # Ask for password for db to be created, defaulting to username
33
+ puts "Password [#{username}]: "
34
+ pass = gets.chomp
35
+ pass = username if pass.nil? || pass.size == 0
36
+
37
+ contents = ""
38
+
39
+ source_file = File.expand_path(File.dirname(__FILE__)) + "/../config/database.yml"
40
+
41
+ File.open(source_file, 'r') do |f1|
42
+ while line = f1.gets
43
+ if line.include?("$")
44
+ line.gsub!(/\$dbname/, dbname) if !line.nil? && !dbname.nil?
45
+ line.gsub!(/\$username/, username) if !line.nil? && !username.nil?
46
+ line.gsub!(/\$password/, pass) if !line.nil? && !pass.nil?
47
+ line.gsub!(/\$dbname_prod/, dbname_prod) if !line.nil? && !pass.nil?
48
+ line.gsub!(/\$dbname_test/, dbname_test) if !line.nil? && !pass.nil?
49
+ end
50
+ contents += line
51
+ end
52
+ end
53
+
54
+ File.open('config/database.yml', 'w') do |f2|
55
+ f2.puts contents
56
+ end
57
+
58
+
59
+ mysql_command = "mysql -u root -p -e \"create database #{dbname}; grant all on #{dbname}.* to #{username}@'localhost' identified by '#{pass}'\";"
60
+ puts "Executing #{mysql_command}"
61
+ system(mysql_command)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'create-rails-dev-db'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCreateRailsDevDb < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: create-rails-dev-db
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Brian Burridge
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-30 00:00:00 -04:00
18
+ default_executable: create-rails-dev-db
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.
33
+ email: bburridg@gmail.com
34
+ executables:
35
+ - create-rails-dev-db
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - bin/create-rails-dev-db
49
+ - config/database.yml
50
+ - create-rails-dev-db.gemspec
51
+ - lib/create-rails-dev-db.rb
52
+ - test/helper.rb
53
+ - test/test_create-rails-dev-db.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/bburridge/create-rails-dev-db
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.6
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: This gem creates the database.yml file for a Rails app and creates the db in mysql and grants the permissions for the user.
84
+ test_files:
85
+ - test/helper.rb
86
+ - test/test_create-rails-dev-db.rb