db-entropy 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.
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ = db-entropy
2
+
3
+ * http://github.com/jayzes/db-entropy
4
+
5
+ == DESCRIPTION:
6
+
7
+ A quick and dirty way to generate random database configuration files for Rails
8
+
9
+ == FEATURES:
10
+
11
+ * Can generate randomized database.yml and mongoid.yml configurations. This is especially useful in CI-type environments where you have the same application running multiple times concurrently and you need to make sure they won't clobber each other.
12
+
13
+ == SYNOPSIS:
14
+
15
+ * rake entropy:randomize_mysql_config will generate a random config/database.yml for MySQL with entries for development, test, and cucumber. Note that test and cucumber will point to the same database.
16
+ * rake entropy:randomize_mongoid_config will generate a random config/mongoid.yml for Mongoid with entries for development, test, and cucumber. Note that test and cucumber will point to the same database.
17
+ * rake entropy:randomize_db_configs will generate both MySQL and Mongoid configurations
18
+
19
+ You may also specify an environment variable (EXTRA_ENVS) as a comma-separated list of additional environments to alias to the test DB. This is useful for master-slave configurations, etc.
20
+
21
+ You'll want to make sure that your build scripts call rake db:create:all after running one of the entropy tasks, and that they call rake db:drop:all after running all tests to make sure you don't leave empty databases hanging around.
22
+
23
+ == REQUIREMENTS:
24
+
25
+ * None
26
+
27
+ == INSTALL:
28
+
29
+ * gem install db-entropy OR add it to your gem bundle
30
+ * If you're using Rails 2.3, add a "require 'db-entropy/tasks'" line to your Rakefile
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2010 Jay Zeschin
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ class DbEntropy::Base
2
+
3
+ attr_accessor :extra_environments
4
+
5
+ def initialize(extra_envs=ENV['EXTRA_ENVS'])
6
+ extra_envs ||= ''
7
+ @extra_environments = (['cucumber'] + extra_envs.split(',')).uniq.compact
8
+ end
9
+
10
+ def generate_random_name(length=10)
11
+ rand(32**length).to_s(32)
12
+ end
13
+
14
+ def generate_yaml(path)
15
+ config = generate_database_config
16
+ write_to_yaml(config,path)
17
+ end
18
+
19
+ def write_to_yaml(db_config,path)
20
+ File.open(path, 'w+') { |out| YAML.dump(db_config, out) }
21
+ end
22
+
23
+ end
@@ -0,0 +1,19 @@
1
+ class DbEntropy::Mongoid < DbEntropy::Base
2
+ def generate_database_config
3
+ db_config = %w(development test).inject({}) do |conf, env|
4
+ conf[env] = {'host' => 'localhost',
5
+ 'allow_dynamic_fields' => true,
6
+ 'parameterize_keys' => true,
7
+ 'persist_in_safe_mode' => true,
8
+ 'raise_not_found_error' => true,
9
+ 'reconnect_time' => 3,
10
+ 'use_object_ids' => false,
11
+ 'database' => "entropy_#{generate_random_name}"}
12
+ conf
13
+ end
14
+ extra_environments.each do |env|
15
+ db_config[env] = db_config['test']
16
+ end
17
+ db_config
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ class DbEntropy::Mysql < DbEntropy::Base
2
+
3
+ def generate_database_config
4
+ db_config = %w(development test).inject({}) do |conf, env|
5
+ conf[env] = {'database' => "entropy_#{generate_random_name}",
6
+ 'adapter' => 'mysql',
7
+ 'hostname' => 'localhost',
8
+ 'username' => 'root',
9
+ 'password' => nil}
10
+ conf
11
+ end
12
+ extra_environments.each do |env|
13
+ db_config[env] = db_config['test']
14
+ end
15
+ db_config
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ class DbEntropy::Mysql2 < DbEntropy::Base
2
+
3
+ def generate_database_config
4
+ db_config = %w(development test).inject({}) do |conf, env|
5
+ conf[env] = {'database' => "entropy_#{generate_random_name}",
6
+ 'adapter' => 'mysql2',
7
+ 'hostname' => 'localhost',
8
+ 'username' => 'root',
9
+ 'password' => nil}
10
+ conf
11
+ end
12
+ extra_environments.each do |env|
13
+ db_config[env] = db_config['test']
14
+ end
15
+ db_config
16
+ end
17
+
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'db-entropy'
2
+
3
+ namespace :entropy do
4
+
5
+ task :randomize_mysql_config do
6
+ DbEntropy::Mysql.new.generate_yaml('config/database.yml')
7
+ end
8
+
9
+ task :randomize_mysql2_config do
10
+ DbEntropy::Mysql2.new.generate_yaml('config/database.yml')
11
+ end
12
+
13
+
14
+ task :randomize_mongoid_config do
15
+ DbEntropy::Mongoid.new.generate_yaml('config/mongoid.yml')
16
+ end
17
+
18
+ task :randomize_db_configs => [:randomize_mysql_config, :randomize_mongoid_config]
19
+
20
+ end
data/lib/db-entropy.rb ADDED
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module DbEntropy
5
+ VERSION = '0.2.1'
6
+ end
7
+
8
+ require 'db-entropy/base'
9
+ require 'db-entropy/mysql'
10
+ require 'db-entropy/mysql2'
11
+ require 'db-entropy/mongoid'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: db-entropy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
11
+ platform: ruby
12
+ authors:
13
+ - Jay Zeschin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-25 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A quick and dirty way to generate random DB configs in Rails
23
+ email:
24
+ - jay.zeschin@factorylabs.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - lib/db-entropy/base.rb
33
+ - lib/db-entropy/mongoid.rb
34
+ - lib/db-entropy/mysql.rb
35
+ - lib/db-entropy/mysql2.rb
36
+ - lib/db-entropy/tasks.rb
37
+ - lib/db-entropy.rb
38
+ - README.rdoc
39
+ has_rdoc: true
40
+ homepage: http://github.com/jayzes/db-entropy
41
+ licenses: []
42
+
43
+ post_install_message: PostInstall.txt
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: A quick and dirty way to generate random database configurations in Rails for testing. Works for MySQL and Mongoid.
73
+ test_files: []
74
+