ar-octopus 0.0.14 → 0.0.15

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
@@ -29,7 +29,7 @@ begin
29
29
  gem.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
30
30
  gem.add_development_dependency "rspec", ">= 1.2.9"
31
31
  gem.add_dependency('activerecord', '>= 3.0.0beta')
32
- gem.version = "0.0.14"
32
+ gem.version = "0.0.15"
33
33
  end
34
34
  Jeweler::GemcutterTasks.new
35
35
  rescue LoadError
data/ar-octopus.gemspec CHANGED
@@ -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.14"
8
+ s.version = "0.0.15"
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-07-01}
12
+ s.date = %q{2010-07-02}
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 = [
data/lib/octopus.rb CHANGED
@@ -2,7 +2,7 @@ require "yaml"
2
2
 
3
3
  module Octopus
4
4
  def self.env()
5
- @env ||= 'octopus'
5
+ @env ||= defined?(Rails) ? Rails.env.to_s : 'octopus'
6
6
  end
7
7
 
8
8
  def self.config()
@@ -23,7 +23,7 @@ module Octopus
23
23
  end
24
24
 
25
25
  def self.excluded_enviroments=(excluded_enviroments)
26
- @excluded_enviroments = excluded_enviroments.map {|element| element.to_s }
26
+ @excluded_enviroments = excluded_enviroments.map { |element| element.to_s }
27
27
  end
28
28
 
29
29
  def self.excluded_enviroments
data/lib/octopus/model.rb CHANGED
@@ -32,7 +32,7 @@ module Octopus::Model
32
32
  before_save :set_connection
33
33
 
34
34
  def set_current_shard
35
- if new_record?
35
+ if new_record? || self.connection.block
36
36
  self.current_shard = self.class.connection_proxy.current_shard
37
37
  else
38
38
  self.current_shard = self.class.connection_proxy.last_current_shard
data/lib/octopus/proxy.rb CHANGED
@@ -151,7 +151,7 @@ class Octopus::Proxy
151
151
  end
152
152
 
153
153
  def should_clean_connection?(method)
154
- method.to_s =~ /insert|select/ && !should_send_queries_to_multiple_shards? && !self.current_group && !@replicated && !self.block
154
+ method.to_s =~ /insert|select|execute/ && !should_send_queries_to_multiple_shards? && !self.current_group && !@replicated && !self.block
155
155
  end
156
156
 
157
157
  def should_send_queries_to_multiple_shards?
@@ -33,12 +33,10 @@ class Octopus::ScopeProxy
33
33
  @klass.connection()
34
34
  end
35
35
 
36
- #TODO - THIS IS UGLY, NEEDS REFACTOR!
37
36
  def method_missing(method, *args, &block)
38
37
  @klass.connection().current_shard = @shard
39
38
  @klass = @klass.send(method, *args, &block)
40
- return nil if @klass.nil?
41
- return @klass if @klass.is_a?(ActiveRecord::Base) or @klass.is_a?(Array) or @klass.is_a?(Fixnum)
39
+ return @klass if @klass.is_a?(ActiveRecord::Base) or @klass.is_a?(Array) or @klass.is_a?(Fixnum) or @klass.nil?
42
40
  return self
43
41
  end
44
42
 
@@ -46,19 +46,6 @@ describe Octopus::Association do
46
46
  k.computer_id.should == c.id
47
47
  k.computer.should == c
48
48
  end
49
-
50
- it "should works when using create!" do
51
- # TODO - This works without octopus?!
52
- # c = Computer.using(:brazil).create!(:name => "Computer Brazil")
53
- # k = c.keyboard.create!(:name => "New Keyboard")
54
- # c.save()
55
- # k.save()
56
- # c.reload()
57
- # k.reload()
58
- # c.keyboard.should == k
59
- # k.computer_id.should == c.id
60
- # k.computer.should == c
61
- end
62
49
  end
63
50
 
64
51
  describe "when you have a N x N reliationship" do
@@ -32,8 +32,6 @@ describe Octopus::Model do
32
32
  end
33
33
 
34
34
  it "should select the correct shard" do
35
- #TODO - Investigate this - why we need to set to master!?
36
- ActiveRecord::Base.connection_proxy.current_shard = :master
37
35
  User.using(:canada)
38
36
  User.create!(:name => 'oi')
39
37
  User.count.should == 1
@@ -45,7 +43,6 @@ describe Octopus::Model do
45
43
  User.using(:master).using(:canada).count.should == 1
46
44
  end
47
45
 
48
-
49
46
  it "should allow find inside blocks" do
50
47
  @user = User.using(:brazil).create!(:name => "Thiago")
51
48
 
@@ -55,7 +52,6 @@ describe Octopus::Model do
55
52
 
56
53
  User.using(:brazil).where(:name => "Thiago").first.should == @user
57
54
  end
58
-
59
55
 
60
56
  it "should clean the current_shard after executing the current query" do
61
57
  User.using(:canada).create!(:name => "oi")
@@ -188,12 +184,13 @@ describe Octopus::Model do
188
184
  end
189
185
 
190
186
  it "using update_attributes inside a block" do
191
- ActiveRecord::Base.connection.run_queries_on_shard :brazil do
187
+ ActiveRecord::Base.using(:brazil) do
192
188
  @user = User.create!(:name => "User1")
193
189
  @user2 = User.find(@user.id)
194
190
  @user2.update_attributes(:name => "Joaquim")
195
191
  end
196
192
 
193
+ User.where(:name => "Joaquim").first.should be_nil
197
194
  User.using(:brazil).where(:name => "Joaquim").first.should_not be_nil
198
195
  end
199
196
 
@@ -205,8 +202,6 @@ describe Octopus::Model do
205
202
  end
206
203
 
207
204
  it "transaction" do
208
- #TODO - Investigate this - why we need to set to master!?
209
- ActiveRecord::Base.connection_proxy.current_shard = :master
210
205
  u = User.create!(:name => "Thiago")
211
206
 
212
207
  User.using(:brazil).count.should == 0
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 14
10
- version: 0.0.14
9
+ - 15
10
+ version: 0.0.15
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-07-01 00:00:00 -03:00
20
+ date: 2010-07-02 00:00:00 -03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency