decisiv-sharded_database 0.1.2 → 0.1.3

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.
@@ -9,7 +9,7 @@ module ShardedDatabase
9
9
  klass.class_eval do
10
10
  cattr_accessor :connection_field, :source_class, :foreign_id
11
11
  @connection_field = :oem
12
- @foreign_id = :foreign_id
12
+ @foreign_id = :other_id
13
13
 
14
14
  class << self
15
15
  alias_method_chain :find, :raw
@@ -24,6 +24,10 @@ module ShardedDatabase
24
24
  @raw ? temporarily_remove(:after_find) { find_without_raw(*args) } : find_without_raw(*args)
25
25
  end
26
26
 
27
+ def preserve_attributes(*attrs)
28
+ @preserved_attributes = attrs.map(&:to_s)
29
+ end
30
+
27
31
  end
28
32
 
29
33
  module InstanceMethods
@@ -39,12 +43,16 @@ module ShardedDatabase
39
43
 
40
44
  metaclass.delegate :connection, :to => @klass
41
45
 
46
+ (self.class.instance_variable_get("@preserved_attributes") || []).each do |attr|
47
+ metaclass.send :alias_method, "proxy_#{attr}", attr
48
+ end
49
+
42
50
  class << self
43
51
  alias_method :proxy_class, :class
44
52
 
45
53
  include AggregateProxy
46
54
  instance_methods.each do |m|
47
- undef_method(m) unless m =~ /^__|proxy_|inspect|foreign_id/
55
+ undef_method(m) unless m =~ /^__|proxy_|inspect/
48
56
  end
49
57
  end
50
58
 
@@ -4,6 +4,6 @@ require 'sharded_database/core_extensions'
4
4
 
5
5
  module ShardedDatabase
6
6
 
7
- VERSION = '0.1'
7
+ VERSION = '0.1.3'
8
8
 
9
9
  end
data/test/lib/models.rb CHANGED
@@ -19,6 +19,8 @@ end
19
19
 
20
20
  class AggregateEstimate < GlobalConnection
21
21
  include ShardedDatabase::Aggregate
22
+ self.foreign_id = :other_id
23
+ preserve_attributes :source
22
24
 
23
25
  def determine_connection
24
26
  Connections[source.to_sym]
@@ -27,7 +27,7 @@ module ShardedDatabase
27
27
  silence do
28
28
  connection.create_table :aggregate_estimates, :force => true do |t|
29
29
  t.string :source
30
- t.integer :foreign_id
30
+ t.integer :other_id
31
31
  t.timestamp :created_at
32
32
  end
33
33
  end
@@ -62,10 +62,10 @@ module ShardedDatabase
62
62
 
63
63
  one_item = Class.new(Connection::One) { set_table_name 'items' ; belongs_to(:estimate) }
64
64
  one_item.create :name => 'One Test Item', :estimate_id => @one_1.id
65
-
66
- AggregateEstimate.create :source => 'one', :foreign_id => @one_1.id
67
- AggregateEstimate.create :source => 'two', :foreign_id => @two_1.id
68
- AggregateEstimate.create :source => 'two', :foreign_id => @two_2.id
65
+
66
+ AggregateEstimate.create :source => 'one', :other_id => @one_1.id
67
+ AggregateEstimate.create :source => 'two', :other_id => @two_1.id
68
+ AggregateEstimate.create :source => 'two', :other_id => @two_2.id
69
69
  end
70
70
 
71
71
  end
@@ -30,6 +30,10 @@ class InstanceTest < ShardedDatabase::TestCase
30
30
  assert_same_elements @estimate.attributes.keys, Estimate.column_names
31
31
  end
32
32
 
33
+ should 'preserve attributes supplied to #preserve_attributes' do
34
+ assert_equal 'one', @estimate.proxy_source
35
+ end
36
+
33
37
  end
34
38
 
35
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decisiv-sharded_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brennan Dunn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-11 00:00:00 -08:00
12
+ date: 2009-01-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15