db-charmer 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,22 @@
1
+ 1.4.6 -> 1.5.0:
2
+
3
+ Major change in this version of DbCharmer is association preload support. For example,
4
+ let's say we have a schema:
5
+
6
+ class Post < ActiveRecord::Base
7
+ belongs_to :user
8
+ end
9
+
10
+ class User < ActiveRecord::Base
11
+ has_many :posts
12
+ end
13
+
14
+ Now, if we have the following call in our code:
15
+
16
+ User.on_db(:foo).all(:include => :posts)
17
+
18
+ In 1.4.6 it would load the users from connection :foo and posts from the
19
+ default connection, which is not what we would expect from this line of code.
20
+ So, starting 1.5.0 all finder calls on models having :include parameter would
21
+ switch associated models' connections to the same connection as the main model
22
+ in the call.
data/Rakefile CHANGED
@@ -9,8 +9,9 @@ begin
9
9
  gemspec.authors = ['Alexey Kovyrin']
10
10
 
11
11
  gemspec.add_dependency('rails', '>= 2.2.0')
12
+ gemspec.add_dependency('blankslate', '>= 0')
12
13
  end
13
14
  Jeweler::GemcutterTasks.new
14
15
  rescue LoadError
15
16
  puts 'Jeweler not available. Install it with: sudo gem install jeweler'
16
- end
17
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.6
1
+ 1.5.0
data/db-charmer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{db-charmer}
8
- s.version = "1.4.6"
8
+ s.version = "1.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexey Kovyrin"]
12
- s.date = %q{2009-11-09}
12
+ s.date = %q{2010-03-05}
13
13
  s.description = %q{ActiveRecord Connections Magic (slaves, multiple connections, etc)}
14
14
  s.email = %q{alexey@kovyrin.net}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
+ "CHANGES",
21
22
  "LICENSE",
22
23
  "Makefile",
23
24
  "README.rdoc",
@@ -27,6 +28,7 @@ Gem::Specification.new do |s|
27
28
  "init.rb",
28
29
  "lib/db_charmer.rb",
29
30
  "lib/db_charmer/active_record_extensions.rb",
31
+ "lib/db_charmer/association_preload.rb",
30
32
  "lib/db_charmer/connection_factory.rb",
31
33
  "lib/db_charmer/connection_proxy.rb",
32
34
  "lib/db_charmer/connection_switch.rb",
@@ -40,7 +42,7 @@ Gem::Specification.new do |s|
40
42
  s.homepage = %q{http://github.com/kovyrin/db-charmer}
41
43
  s.rdoc_options = ["--charset=UTF-8"]
42
44
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.5}
45
+ s.rubygems_version = %q{1.3.6}
44
46
  s.summary = %q{ActiveRecord Connections Magic}
45
47
 
46
48
  if s.respond_to? :specification_version then
@@ -49,11 +51,14 @@ Gem::Specification.new do |s|
49
51
 
50
52
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
53
  s.add_runtime_dependency(%q<rails>, [">= 2.2.0"])
54
+ s.add_runtime_dependency(%q<blankslate>, [">= 0"])
52
55
  else
53
56
  s.add_dependency(%q<rails>, [">= 2.2.0"])
57
+ s.add_dependency(%q<blankslate>, [">= 0"])
54
58
  end
55
59
  else
56
60
  s.add_dependency(%q<rails>, [">= 2.2.0"])
61
+ s.add_dependency(%q<blankslate>, [">= 0"])
57
62
  end
58
63
  end
59
64
 
data/lib/db_charmer.rb CHANGED
@@ -31,6 +31,9 @@ class Object
31
31
  end
32
32
  end
33
33
 
34
+ # We need blankslate for all the proxies we have
35
+ require 'blankslate'
36
+
34
37
  #puts "Extending AR..."
35
38
 
36
39
  require 'db_charmer/active_record_extensions'
@@ -83,6 +86,7 @@ end
83
86
 
84
87
  require 'db_charmer/db_magic'
85
88
  require 'db_charmer/finder_overrides'
89
+ require 'db_charmer/association_preload'
86
90
  require 'db_charmer/multi_db_migrations'
87
91
  require 'db_charmer/multi_db_proxy'
88
92
 
@@ -91,3 +95,6 @@ ActiveRecord::Migration.extend(DbCharmer::MultiDbMigrations)
91
95
 
92
96
  # Enable the magic
93
97
  ActiveRecord::Base.extend(DbCharmer::DbMagic::ClassMethods)
98
+
99
+ # Setup association preload magic
100
+ ActiveRecord::Base.extend(DbCharmer::AssociationPreload::ClassMethods)
@@ -0,0 +1,17 @@
1
+ module DbCharmer
2
+ module AssociationPreload
3
+ module ClassMethods
4
+ ASSOCIATION_TYPES = [ :has_one, :has_many, :belongs_to, :has_and_belongs_to_many ]
5
+ ASSOCIATION_TYPES.each do |association_type|
6
+ class_eval <<-EOF, __FILE__, __LINE__ + 1
7
+ def preload_#{association_type}_association(records, reflection, preload_options = {})
8
+ return super(records, reflection, preload_options) if self.db_charmer_top_level_connection?
9
+ reflection.klass.on_db(self) do
10
+ super(records, reflection, preload_options)
11
+ end
12
+ end
13
+ EOF
14
+ end
15
+ end
16
+ end
17
+ end
@@ -15,7 +15,7 @@ module DbCharmer
15
15
  opt[:slaves] ||= []
16
16
  opt[:slaves] << opt[:slave] if opt[:slave]
17
17
  db_magic_slaves(opt[:slaves], should_exist) if opt[:slaves].any?
18
-
18
+
19
19
  # Setup inheritance magic
20
20
  setup_children_magic(opt)
21
21
  end
@@ -24,7 +24,7 @@ module DbCharmer
24
24
 
25
25
  def setup_children_magic(opt)
26
26
  self.db_charmer_opts = opt.clone
27
-
27
+
28
28
  def self.inherited(child)
29
29
  child.db_magic(self.db_charmer_opts)
30
30
  super
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-charmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 5
8
+ - 0
9
+ version: 1.5.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Alexey Kovyrin
@@ -9,19 +14,35 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-09 00:00:00 -05:00
17
+ date: 2010-03-05 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rails
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 2
30
+ - 0
23
31
  version: 2.2.0
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: blankslate
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
25
46
  description: ActiveRecord Connections Magic (slaves, multiple connections, etc)
26
47
  email: alexey@kovyrin.net
27
48
  executables: []
@@ -33,6 +54,7 @@ extra_rdoc_files:
33
54
  - README.rdoc
34
55
  files:
35
56
  - .gitignore
57
+ - CHANGES
36
58
  - LICENSE
37
59
  - Makefile
38
60
  - README.rdoc
@@ -42,6 +64,7 @@ files:
42
64
  - init.rb
43
65
  - lib/db_charmer.rb
44
66
  - lib/db_charmer/active_record_extensions.rb
67
+ - lib/db_charmer/association_preload.rb
45
68
  - lib/db_charmer/connection_factory.rb
46
69
  - lib/db_charmer/connection_proxy.rb
47
70
  - lib/db_charmer/connection_switch.rb
@@ -64,18 +87,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
87
  requirements:
65
88
  - - ">="
66
89
  - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
67
92
  version: "0"
68
- version:
69
93
  required_rubygems_version: !ruby/object:Gem::Requirement
70
94
  requirements:
71
95
  - - ">="
72
96
  - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
73
99
  version: "0"
74
- version:
75
100
  requirements: []
76
101
 
77
102
  rubyforge_project:
78
- rubygems_version: 1.3.5
103
+ rubygems_version: 1.3.6
79
104
  signing_key:
80
105
  specification_version: 3
81
106
  summary: ActiveRecord Connections Magic