ar-octopus 0.0.3 → 0.0.4

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/Rakefile CHANGED
@@ -28,7 +28,7 @@ begin
28
28
  gem.homepage = "http://github.com/tchandy/octopus"
29
29
  gem.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
30
30
  gem.add_development_dependency "rspec", ">= 1.2.9"
31
- gem.version = "0.0.3"
31
+ gem.version = "0.0.4"
32
32
  end
33
33
  Jeweler::GemcutterTasks.new
34
34
  rescue LoadError
@@ -62,7 +62,7 @@ Rake::RDocTask.new do |rdoc|
62
62
  end
63
63
 
64
64
  namespace :db do
65
- desc 'Build the MySQL test databases'
65
+ desc 'Build the databases for tests'
66
66
  task :build_databases do
67
67
  mysql_user = ENV['MYSQL_USER'] || "root"
68
68
  postgres_user = ENV['POSTGRES_USER'] || "postgres"
@@ -73,7 +73,7 @@ namespace :db do
73
73
  %x( createdb -E UTF8 -U #{postgres_user} octopus_shard1 )
74
74
  end
75
75
 
76
- desc 'Drop the MySQL test databases'
76
+ desc 'Drop the tests databases'
77
77
  task :drop_databases do
78
78
  mysql_user = ENV['MYSQL_USER'] || "root"
79
79
  postgres_user = ENV['POSTGRES_USER'] || "postgres"
@@ -84,7 +84,7 @@ namespace :db do
84
84
  %x( dropdb -U #{postgres_user} octopus_shard1 )
85
85
  end
86
86
 
87
- desc 'Create tables on mysql databases'
87
+ desc 'Create tables on tests databases'
88
88
  task :create_tables do
89
89
  Dir.chdir(File.expand_path(File.dirname(__FILE__) + "/spec"))
90
90
  require "database_connection"
@@ -151,7 +151,7 @@ namespace :db do
151
151
  end
152
152
  end
153
153
 
154
- desc 'Prepare the MySQL test databases'
154
+ desc 'Prepare the test databases'
155
155
  task :prepare => [:drop_databases, :build_databases, :create_tables]
156
156
  end
157
157
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ar-octopus}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
12
- s.date = %q{2010-06-22}
12
+ s.date = %q{2010-06-23}
13
13
  s.description = %q{This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards.}
14
14
  s.email = %q{tchandy@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/octopus/migration.rb",
34
34
  "lib/octopus/model.rb",
35
35
  "lib/octopus/proxy.rb",
36
+ "rails/init.rb",
36
37
  "spec/config/shards.yml",
37
38
  "spec/database_connection.rb",
38
39
  "spec/database_models.rb",
@@ -53,6 +54,7 @@ Gem::Specification.new do |s|
53
54
  "spec/octopus/model_spec.rb",
54
55
  "spec/octopus/octopus_spec.rb",
55
56
  "spec/octopus/proxy_spec.rb",
57
+ "spec/octopus_helper.rb",
56
58
  "spec/spec.opts",
57
59
  "spec/spec_helper.rb"
58
60
  ]
@@ -81,6 +83,7 @@ Gem::Specification.new do |s|
81
83
  "spec/octopus/model_spec.rb",
82
84
  "spec/octopus/octopus_spec.rb",
83
85
  "spec/octopus/proxy_spec.rb",
86
+ "spec/octopus_helper.rb",
84
87
  "spec/spec_helper.rb"
85
88
  ]
86
89
 
@@ -1,6 +1,7 @@
1
1
  module Octopus::Model
2
2
  def self.extended(base)
3
3
  base.send(:include, InstanceMethods)
4
+ base.hijack_connection()
4
5
  end
5
6
 
6
7
  module InstanceMethods
@@ -0,0 +1 @@
1
+ require "octopus"
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'active_record'
3
- require 'logger'
4
3
  require "pg"
5
4
 
6
5
  ActiveRecord::Base.establish_connection(:adapter => "mysql", :database => "octopus_shard1", :username => "root", :password => "")
@@ -0,0 +1,31 @@
1
+ def clean_all_shards()
2
+ ActiveRecord::Base.using(:master).connection.shards.keys.each do |shard_symbol|
3
+ ['schema_migrations', 'users', 'clients', 'cats', 'items', 'keyboards', 'computers', 'permissions_roles', 'roles', 'permissions', 'assignments', 'projects', 'programmers'].each do |tables|
4
+ ActiveRecord::Base.using(shard_symbol).connection.execute("DELETE FROM #{tables};")
5
+ end
6
+ end
7
+ end
8
+
9
+ def clean_connection_proxy()
10
+ Thread.current[:connection_proxy] = nil
11
+ end
12
+
13
+ def migrating_to_version(version, &block)
14
+ begin
15
+ ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, version)
16
+ yield
17
+ ensure
18
+ ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, version)
19
+ end
20
+ end
21
+
22
+ def using_enviroment(enviroment, &block)
23
+ begin
24
+ Octopus.instance_variable_set(:@env, enviroment.to_s)
25
+ clean_connection_proxy()
26
+ yield
27
+ ensure
28
+ Octopus.instance_variable_set(:@env, 'production')
29
+ clean_connection_proxy()
30
+ end
31
+ end
@@ -5,6 +5,7 @@ require "spec/database_connection"
5
5
  require "action_pack"
6
6
  require "action_controller"
7
7
  require 'octopus'
8
+ require "octopus_helper"
8
9
 
9
10
  Spec::Runner.configure do |config|
10
11
  config.mock_with :rspec
@@ -18,36 +19,4 @@ Spec::Runner.configure do |config|
18
19
  config.after(:each) do
19
20
  clean_all_shards()
20
21
  end
21
- end
22
-
23
- def clean_all_shards()
24
- ActiveRecord::Base.using(:master).connection.shards.keys.each do |shard_symbol|
25
- ['schema_migrations', 'users', 'clients', 'cats', 'items', 'keyboards', 'computers', 'permissions_roles', 'roles', 'permissions', 'assignments', 'projects', 'programmers'].each do |tables|
26
- ActiveRecord::Base.using(shard_symbol).connection.execute("DELETE FROM #{tables};")
27
- end
28
- end
29
- end
30
-
31
- def migrating_to_version(version, &block)
32
- begin
33
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, version)
34
- yield
35
- ensure
36
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, version)
37
- end
38
- end
39
-
40
- def clean_connection_proxy()
41
- Thread.current[:connection_proxy] = nil
42
- end
43
-
44
- def using_enviroment(enviroment, &block)
45
- begin
46
- Octopus.instance_variable_set(:@env, enviroment.to_s)
47
- clean_connection_proxy()
48
- yield
49
- ensure
50
- Octopus.instance_variable_set(:@env, 'production')
51
- clean_connection_proxy()
52
- end
53
22
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-octopus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thiago Pradi
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-22 00:00:00 -03:00
20
+ date: 2010-06-23 00:00:00 -03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,7 @@ files:
62
62
  - lib/octopus/migration.rb
63
63
  - lib/octopus/model.rb
64
64
  - lib/octopus/proxy.rb
65
+ - rails/init.rb
65
66
  - spec/config/shards.yml
66
67
  - spec/database_connection.rb
67
68
  - spec/database_models.rb
@@ -82,6 +83,7 @@ files:
82
83
  - spec/octopus/model_spec.rb
83
84
  - spec/octopus/octopus_spec.rb
84
85
  - spec/octopus/proxy_spec.rb
86
+ - spec/octopus_helper.rb
85
87
  - spec/spec.opts
86
88
  - spec/spec_helper.rb
87
89
  has_rdoc: true
@@ -138,4 +140,5 @@ test_files:
138
140
  - spec/octopus/model_spec.rb
139
141
  - spec/octopus/octopus_spec.rb
140
142
  - spec/octopus/proxy_spec.rb
143
+ - spec/octopus_helper.rb
141
144
  - spec/spec_helper.rb