xbar 0.0.1 → 0.4.0

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.
Files changed (80) hide show
  1. data/Appraisals +25 -0
  2. data/README.mkdn +215 -0
  3. data/Rakefile +337 -1
  4. data/examples/README +5 -0
  5. data/examples/config/simple.json +22 -0
  6. data/examples/example1.rb +34 -0
  7. data/examples/migrations/1_create_users.rb +10 -0
  8. data/examples/setup.rb +43 -0
  9. data/gemfiles/rails3.gemfile +8 -0
  10. data/gemfiles/rails3.gemfile.lock +74 -0
  11. data/gemfiles/rails31.gemfile +8 -0
  12. data/gemfiles/rails31.gemfile.lock +83 -0
  13. data/gemfiles/rails32.gemfile +7 -0
  14. data/gemfiles/rails32.gemfile.lock +117 -0
  15. data/gemfiles/rails4.gemfile +9 -0
  16. data/gemfiles/rails4.gemfile.lock +134 -0
  17. data/lib/migrations/1_create_usage_statistics.rb +23 -0
  18. data/lib/xbar/association.rb +49 -0
  19. data/lib/xbar/association_collection.rb +69 -0
  20. data/lib/xbar/colors.rb +32 -0
  21. data/lib/xbar/has_and_belongs_to_many_association.rb +17 -0
  22. data/lib/xbar/logger.rb +14 -0
  23. data/lib/xbar/mapper.rb +304 -0
  24. data/lib/xbar/migration.rb +76 -0
  25. data/lib/xbar/model.rb +165 -0
  26. data/lib/xbar/proxy.rb +249 -0
  27. data/lib/xbar/rails2/association.rb +133 -0
  28. data/lib/xbar/rails2/persistence.rb +39 -0
  29. data/lib/xbar/rails3/arel.rb +13 -0
  30. data/lib/xbar/rails3/association.rb +112 -0
  31. data/lib/xbar/rails3/persistence.rb +37 -0
  32. data/lib/xbar/rails3.1/singular_association.rb +34 -0
  33. data/lib/xbar/scope_proxy.rb +55 -0
  34. data/lib/xbar/shard.rb +95 -0
  35. data/lib/xbar/version.rb +2 -2
  36. data/lib/xbar.rb +121 -2
  37. data/run +27 -0
  38. data/spec/config/acme.json +53 -0
  39. data/spec/config/connection.rb +2 -0
  40. data/spec/config/default.json +160 -0
  41. data/spec/config/duplicate_shard.json +21 -0
  42. data/spec/config/missing_key.json +20 -0
  43. data/spec/config/new_shards.json +29 -0
  44. data/spec/config/no_master_shard.json +19 -0
  45. data/spec/config/not_entire_sharded.json +23 -0
  46. data/spec/config/octopus.json +27 -0
  47. data/spec/config/octopus_rails.json +25 -0
  48. data/spec/config/production_fully_replicated.json +21 -0
  49. data/spec/config/production_raise_error.json +17 -0
  50. data/spec/config/simple.json +22 -0
  51. data/spec/config/single_adapter.json +20 -0
  52. data/spec/console.rb +15 -0
  53. data/spec/migrations/10_create_users_using_replication.rb +12 -0
  54. data/spec/migrations/11_add_field_in_all_slaves.rb +11 -0
  55. data/spec/migrations/12_create_users_using_block.rb +23 -0
  56. data/spec/migrations/13_create_users_using_block_and_using.rb +15 -0
  57. data/spec/migrations/1_create_users_on_master.rb +9 -0
  58. data/spec/migrations/2_create_users_on_canada.rb +11 -0
  59. data/spec/migrations/3_create_users_on_both_shards.rb +11 -0
  60. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +11 -0
  61. data/spec/migrations/5_create_users_on_multiples_groups.rb +11 -0
  62. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +11 -0
  63. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +11 -0
  64. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +11 -0
  65. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +11 -0
  66. data/spec/spec_helper.rb +25 -0
  67. data/spec/support/database_models.rb +78 -0
  68. data/spec/support/xbar_helper.rb +42 -0
  69. data/spec/xbar/association_spec.rb +660 -0
  70. data/spec/xbar/controller_spec.rb +40 -0
  71. data/spec/xbar/logger_spec.rb +22 -0
  72. data/spec/xbar/mapper_spec.rb +283 -0
  73. data/spec/xbar/migration_spec.rb +110 -0
  74. data/spec/xbar/model_spec.rb +434 -0
  75. data/spec/xbar/proxy_spec.rb +124 -0
  76. data/spec/xbar/replication_spec.rb +94 -0
  77. data/spec/xbar/scope_proxy_spec.rb +22 -0
  78. data/spec/xbar/shard_spec.rb +36 -0
  79. data/xbar.gemspec +13 -3
  80. metadata +231 -10
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.0.11"
6
+ gem "actionpack", "~> 3.0.11"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: /Volumes/Opt/projects/xbar
3
+ specs:
4
+ xbar (0.4.0)
5
+ activerecord
6
+ mysql2
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionpack (3.0.11)
13
+ activemodel (= 3.0.11)
14
+ activesupport (= 3.0.11)
15
+ builder (~> 2.1.2)
16
+ erubis (~> 2.6.6)
17
+ i18n (~> 0.5.0)
18
+ rack (~> 1.2.1)
19
+ rack-mount (~> 0.6.14)
20
+ rack-test (~> 0.5.7)
21
+ tzinfo (~> 0.3.23)
22
+ activemodel (3.0.11)
23
+ activesupport (= 3.0.11)
24
+ builder (~> 2.1.2)
25
+ i18n (~> 0.5.0)
26
+ activerecord (3.0.11)
27
+ activemodel (= 3.0.11)
28
+ activesupport (= 3.0.11)
29
+ arel (~> 2.0.10)
30
+ tzinfo (~> 0.3.23)
31
+ activesupport (3.0.11)
32
+ appraisal (0.4.0)
33
+ bundler
34
+ rake
35
+ arel (2.0.10)
36
+ builder (2.1.2)
37
+ diff-lcs (1.1.3)
38
+ erubis (2.6.6)
39
+ abstract (>= 1.0.0)
40
+ i18n (0.5.0)
41
+ mysql2 (0.3.11)
42
+ pg (0.12.2)
43
+ rack (1.2.5)
44
+ rack-mount (0.6.14)
45
+ rack (>= 1.0.0)
46
+ rack-test (0.5.7)
47
+ rack (>= 1.0)
48
+ rake (0.9.2.2)
49
+ rspec (2.8.0)
50
+ rspec-core (~> 2.8.0)
51
+ rspec-expectations (~> 2.8.0)
52
+ rspec-mocks (~> 2.8.0)
53
+ rspec-core (2.8.0)
54
+ rspec-expectations (2.8.0)
55
+ diff-lcs (~> 1.1.2)
56
+ rspec-mocks (2.8.0)
57
+ sqlite3 (1.3.5)
58
+ syntax (1.0.0)
59
+ tzinfo (0.3.31)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ actionpack (~> 3.0.11)
66
+ activerecord (~> 3.0.11)
67
+ appraisal
68
+ mysql2
69
+ pg
70
+ rake
71
+ rspec (= 2.8.0)
72
+ sqlite3
73
+ syntax
74
+ xbar!
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.1.1"
6
+ gem "actionpack", "~> 3.1.1"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: /Volumes/Opt/projects/xbar
3
+ specs:
4
+ xbar (0.4.0)
5
+ activerecord
6
+ mysql2
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionpack (3.1.3)
12
+ activemodel (= 3.1.3)
13
+ activesupport (= 3.1.3)
14
+ builder (~> 3.0.0)
15
+ erubis (~> 2.7.0)
16
+ i18n (~> 0.6)
17
+ rack (~> 1.3.5)
18
+ rack-cache (~> 1.1)
19
+ rack-mount (~> 0.8.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.0.3)
22
+ activemodel (3.1.3)
23
+ activesupport (= 3.1.3)
24
+ builder (~> 3.0.0)
25
+ i18n (~> 0.6)
26
+ activerecord (3.1.3)
27
+ activemodel (= 3.1.3)
28
+ activesupport (= 3.1.3)
29
+ arel (~> 2.2.1)
30
+ tzinfo (~> 0.3.29)
31
+ activesupport (3.1.3)
32
+ multi_json (~> 1.0)
33
+ appraisal (0.4.0)
34
+ bundler
35
+ rake
36
+ arel (2.2.1)
37
+ builder (3.0.0)
38
+ diff-lcs (1.1.3)
39
+ erubis (2.7.0)
40
+ hike (1.2.1)
41
+ i18n (0.6.0)
42
+ multi_json (1.0.4)
43
+ mysql2 (0.3.11)
44
+ pg (0.12.2)
45
+ rack (1.3.6)
46
+ rack-cache (1.1)
47
+ rack (>= 0.4)
48
+ rack-mount (0.8.3)
49
+ rack (>= 1.0.0)
50
+ rack-test (0.6.1)
51
+ rack (>= 1.0)
52
+ rake (0.9.2.2)
53
+ rspec (2.8.0)
54
+ rspec-core (~> 2.8.0)
55
+ rspec-expectations (~> 2.8.0)
56
+ rspec-mocks (~> 2.8.0)
57
+ rspec-core (2.8.0)
58
+ rspec-expectations (2.8.0)
59
+ diff-lcs (~> 1.1.2)
60
+ rspec-mocks (2.8.0)
61
+ sprockets (2.0.3)
62
+ hike (~> 1.2)
63
+ rack (~> 1.0)
64
+ tilt (~> 1.1, != 1.3.0)
65
+ sqlite3 (1.3.5)
66
+ syntax (1.0.0)
67
+ tilt (1.3.3)
68
+ tzinfo (0.3.31)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ actionpack (~> 3.1.1)
75
+ activerecord (~> 3.1.1)
76
+ appraisal
77
+ mysql2
78
+ pg
79
+ rake
80
+ rspec (= 2.8.0)
81
+ sqlite3
82
+ syntax
83
+ xbar!
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.2.1"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: /opt/projects/xbar
3
+ specs:
4
+ xbar (0.4.0)
5
+ activerecord
6
+ mysql2
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.1)
12
+ actionpack (= 3.2.1)
13
+ mail (~> 2.4.0)
14
+ actionpack (3.2.1)
15
+ activemodel (= 3.2.1)
16
+ activesupport (= 3.2.1)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.1)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.1)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.2)
24
+ activemodel (3.2.1)
25
+ activesupport (= 3.2.1)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.1)
28
+ activemodel (= 3.2.1)
29
+ activesupport (= 3.2.1)
30
+ arel (~> 3.0.0)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.1)
33
+ activemodel (= 3.2.1)
34
+ activesupport (= 3.2.1)
35
+ activesupport (3.2.1)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ appraisal (0.4.0)
39
+ bundler
40
+ rake
41
+ arel (3.0.0)
42
+ builder (3.0.0)
43
+ diff-lcs (1.1.3)
44
+ erubis (2.7.0)
45
+ hike (1.2.1)
46
+ i18n (0.6.0)
47
+ journey (1.0.1)
48
+ json (1.6.5)
49
+ mail (2.4.1)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ mime-types (1.17.2)
54
+ multi_json (1.0.4)
55
+ mysql2 (0.3.11)
56
+ pg (0.12.2)
57
+ polyglot (0.3.3)
58
+ rack (1.4.1)
59
+ rack-cache (1.1)
60
+ rack (>= 0.4)
61
+ rack-ssl (1.3.2)
62
+ rack
63
+ rack-test (0.6.1)
64
+ rack (>= 1.0)
65
+ rails (3.2.1)
66
+ actionmailer (= 3.2.1)
67
+ actionpack (= 3.2.1)
68
+ activerecord (= 3.2.1)
69
+ activeresource (= 3.2.1)
70
+ activesupport (= 3.2.1)
71
+ bundler (~> 1.0)
72
+ railties (= 3.2.1)
73
+ railties (3.2.1)
74
+ actionpack (= 3.2.1)
75
+ activesupport (= 3.2.1)
76
+ rack-ssl (~> 1.3.2)
77
+ rake (>= 0.8.7)
78
+ rdoc (~> 3.4)
79
+ thor (~> 0.14.6)
80
+ rake (0.9.2.2)
81
+ rdoc (3.12)
82
+ json (~> 1.4)
83
+ rspec (2.8.0)
84
+ rspec-core (~> 2.8.0)
85
+ rspec-expectations (~> 2.8.0)
86
+ rspec-mocks (~> 2.8.0)
87
+ rspec-core (2.8.0)
88
+ rspec-expectations (2.8.0)
89
+ diff-lcs (~> 1.1.2)
90
+ rspec-mocks (2.8.0)
91
+ sprockets (2.1.2)
92
+ hike (~> 1.2)
93
+ rack (~> 1.0)
94
+ tilt (~> 1.1, != 1.3.0)
95
+ sqlite3 (1.3.5)
96
+ syntax (1.0.0)
97
+ thor (0.14.6)
98
+ tilt (1.3.3)
99
+ treetop (1.4.10)
100
+ polyglot
101
+ polyglot (>= 0.3.1)
102
+ tzinfo (0.3.31)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ actionpack
109
+ appraisal
110
+ mysql2
111
+ pg
112
+ rails (= 3.2.1)
113
+ rake
114
+ rspec (= 2.8.0)
115
+ sqlite3
116
+ syntax
117
+ xbar!
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", :path=>"/opt/rails/rails-edge"
6
+ gem "journey", :git=>"https://github.com/rails/journey.git"
7
+ gem "arel", :git=>"https://github.com/rails/arel.git"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,134 @@
1
+ GIT
2
+ remote: https://github.com/rails/arel.git
3
+ revision: fc787a42c0febcee41e13d16e06b72492ab00468
4
+ specs:
5
+ arel (3.0.0.20120112113618)
6
+
7
+ GIT
8
+ remote: https://github.com/rails/journey.git
9
+ revision: 7059e60070861a9c364a50954ee4abb355cc4541
10
+ specs:
11
+ journey (1.0.1.20120126102309)
12
+
13
+ PATH
14
+ remote: /Volumes/Opt/projects/xbar
15
+ specs:
16
+ xbar (0.4.0)
17
+ activerecord
18
+ mysql2
19
+
20
+ PATH
21
+ remote: /opt/rails/rails-edge
22
+ specs:
23
+ actionmailer (4.0.0.beta)
24
+ actionpack (= 4.0.0.beta)
25
+ mail (~> 2.4.1)
26
+ actionpack (4.0.0.beta)
27
+ activemodel (= 4.0.0.beta)
28
+ activesupport (= 4.0.0.beta)
29
+ builder (~> 3.0.0)
30
+ erubis (~> 2.7.0)
31
+ journey (~> 1.0.1)
32
+ rack (~> 1.4.1)
33
+ rack-cache (~> 1.1)
34
+ rack-test (~> 0.6.1)
35
+ sprockets (~> 2.2.0)
36
+ activemodel (4.0.0.beta)
37
+ activesupport (= 4.0.0.beta)
38
+ builder (~> 3.0.0)
39
+ activerecord (4.0.0.beta)
40
+ activemodel (= 4.0.0.beta)
41
+ activesupport (= 4.0.0.beta)
42
+ arel (~> 3.0.0)
43
+ tzinfo (~> 0.3.29)
44
+ activeresource (4.0.0.beta)
45
+ activemodel (= 4.0.0.beta)
46
+ activesupport (= 4.0.0.beta)
47
+ activesupport (4.0.0.beta)
48
+ i18n (~> 0.6)
49
+ multi_json (~> 1.0)
50
+ rails (4.0.0.beta)
51
+ actionmailer (= 4.0.0.beta)
52
+ actionpack (= 4.0.0.beta)
53
+ activerecord (= 4.0.0.beta)
54
+ activeresource (= 4.0.0.beta)
55
+ activesupport (= 4.0.0.beta)
56
+ bundler (~> 1.0)
57
+ railties (= 4.0.0.beta)
58
+ railties (4.0.0.beta)
59
+ actionpack (= 4.0.0.beta)
60
+ activesupport (= 4.0.0.beta)
61
+ rack-ssl (~> 1.3.2)
62
+ rake (>= 0.8.7)
63
+ rdoc (~> 3.4)
64
+ thor (~> 0.14.6)
65
+
66
+ GEM
67
+ remote: http://rubygems.org/
68
+ specs:
69
+ appraisal (0.4.0)
70
+ bundler
71
+ rake
72
+ builder (3.0.0)
73
+ diff-lcs (1.1.3)
74
+ erubis (2.7.0)
75
+ hike (1.2.1)
76
+ i18n (0.6.0)
77
+ json (1.6.5)
78
+ mail (2.4.1)
79
+ i18n (>= 0.4.0)
80
+ mime-types (~> 1.16)
81
+ treetop (~> 1.4.8)
82
+ mime-types (1.17.2)
83
+ multi_json (1.0.4)
84
+ mysql2 (0.3.11)
85
+ pg (0.12.2)
86
+ polyglot (0.3.3)
87
+ rack (1.4.1)
88
+ rack-cache (1.1)
89
+ rack (>= 0.4)
90
+ rack-ssl (1.3.2)
91
+ rack
92
+ rack-test (0.6.1)
93
+ rack (>= 1.0)
94
+ rake (0.9.2.2)
95
+ rdoc (3.12)
96
+ json (~> 1.4)
97
+ rspec (2.8.0)
98
+ rspec-core (~> 2.8.0)
99
+ rspec-expectations (~> 2.8.0)
100
+ rspec-mocks (~> 2.8.0)
101
+ rspec-core (2.8.0)
102
+ rspec-expectations (2.8.0)
103
+ diff-lcs (~> 1.1.2)
104
+ rspec-mocks (2.8.0)
105
+ sprockets (2.2.0)
106
+ hike (~> 1.2)
107
+ multi_json (~> 1.0)
108
+ rack (~> 1.0)
109
+ tilt (~> 1.1, != 1.3.0)
110
+ sqlite3 (1.3.5)
111
+ syntax (1.0.0)
112
+ thor (0.14.6)
113
+ tilt (1.3.3)
114
+ treetop (1.4.10)
115
+ polyglot
116
+ polyglot (>= 0.3.1)
117
+ tzinfo (0.3.31)
118
+
119
+ PLATFORMS
120
+ ruby
121
+
122
+ DEPENDENCIES
123
+ actionpack
124
+ appraisal
125
+ arel!
126
+ journey!
127
+ mysql2
128
+ pg
129
+ rails!
130
+ rake
131
+ rspec (= 2.8.0)
132
+ sqlite3
133
+ syntax
134
+ xbar!
@@ -0,0 +1,23 @@
1
+ class CreateUsageStatistics < ActiveRecord::Migration
2
+
3
+ def up
4
+ create_table(:usage_statistics) do |t|
5
+ t.string :shard_name
6
+ t.string :method
7
+ t.string :adapter
8
+ t.string :username
9
+ t.string :thread_id
10
+ t.integer :port
11
+ t.string :host
12
+ t.string :database_name
13
+ end
14
+ end
15
+
16
+ def down
17
+ puts "Dropping table..."
18
+ drop_table(:usage_statistics)
19
+ puts "Done dropping table."
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,49 @@
1
+ require 'active_support/concern'
2
+
3
+ module XBar::Association
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def has_many(association_id, options = {}, &extension)
9
+ default_xbar_opts(options)
10
+ super
11
+ end
12
+
13
+ def has_and_belongs_to_many(association_id, options = {}, &extension)
14
+ default_xbar_opts(options)
15
+ super
16
+ end
17
+
18
+ def default_xbar_opts(options)
19
+ if options[:before_add].is_a?(Array)
20
+ options[:before_add] << :set_connection_on_association
21
+ elsif options[:before_add].is_a?(Symbol)
22
+ options[:before_add] = [:set_connection_on_association, options[:before_add]]
23
+ else
24
+ options[:before_add] = :set_connection_on_association
25
+ end
26
+
27
+ if options[:before_remove].is_a?(Array)
28
+ options[:before_remove] << :set_connection_on_association
29
+ elsif options[:before_remove].is_a?(Symbol)
30
+ options[:before_remove] = [:set_connection_on_association, options[:before_remove]]
31
+ else
32
+ options[:before_remove] = :set_connection_on_association
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def set_connection_on_association(record)
40
+ return if !self.connection.respond_to?(:current_shard) || !self.respond_to?(:current_shard)
41
+ if !record.current_shard.nil? && !self.current_shard.nil? && record.current_shard != self.current_shard
42
+ raise "Association Error: Records are from different shards"
43
+ end
44
+ record.current_shard = self.connection.current_shard = self.current_shard if should_set_current_shard?
45
+ end
46
+
47
+ end
48
+
49
+ ActiveRecord::Base.send(:include, XBar::Association)
@@ -0,0 +1,69 @@
1
+ module XBar::AssociationCollection
2
+
3
+ def self.included(base)
4
+ if XBar.rails31?
5
+ base.instance_eval do
6
+ alias_method_chain :reader, :xbar
7
+ alias_method_chain :writer, :xbar
8
+ alias_method_chain :ids_reader, :xbar
9
+ alias_method_chain :ids_writer, :xbar
10
+ alias_method_chain :create, :xbar
11
+ alias_method_chain :create!, :xbar
12
+ alias_method_chain :build, :xbar
13
+ end
14
+ end
15
+ end
16
+
17
+ def build_with_xbar(*args)
18
+ owner.reload_connection
19
+ build_without_xbar(*args)
20
+ end
21
+
22
+ def reader_with_xbar(*args)
23
+ owner.reload_connection
24
+ reader_without_xbar(*args)
25
+ end
26
+
27
+ def writer_with_xbar(*args)
28
+ owner.reload_connection
29
+ writer_without_xbar(*args)
30
+ end
31
+
32
+ def ids_reader_with_xbar(*args)
33
+ owner.reload_connection
34
+ ids_reader_without_xbar(*args)
35
+ end
36
+
37
+ def ids_writer_with_xbar(*args)
38
+ owner.reload_connection
39
+ ids_writer_without_xbar(*args)
40
+ end
41
+
42
+ def create_with_xbar(*args)
43
+ owner.reload_connection
44
+ create_without_xbar(*args)
45
+ end
46
+
47
+ def create_with_xbar!(*args)
48
+ owner.reload_connection
49
+ create_without_xbar!(*args)
50
+ end
51
+
52
+ def should_wrap_the_connection?
53
+ @owner.respond_to?(:current_shard) && @owner.current_shard != nil
54
+ end
55
+
56
+ def count(*args)
57
+ if should_wrap_the_connection?
58
+ XBar.using(@owner.current_shard) { super }
59
+ else
60
+ super
61
+ end
62
+ end
63
+ end
64
+
65
+ if XBar.rails31?
66
+ ActiveRecord::Associations::CollectionAssociation.send(:include, XBar::AssociationCollection)
67
+ else
68
+ ActiveRecord::Associations::AssociationCollection.send(:include, XBar::AssociationCollection)
69
+ end
@@ -0,0 +1,32 @@
1
+ module Colors
2
+
3
+ # foreground color
4
+ BLACK_TEXT = "\033[30m"
5
+ RED_TEXT = "\033[31m"
6
+ GREEN_TEXT = "\033[32m"
7
+ BROWN_TEXT = "\033[33m"
8
+ BLUE_TEXT = "\033[34m"
9
+ MAGENTA_TEXT = "\033[35m"
10
+ CYAN_TEXT = "\033[36m"
11
+ GRAY_TEXT = "\033[37m"
12
+
13
+ # background color
14
+ BLACK_BACK = "\033[40m"
15
+ RED_BACK = "\033[41m"
16
+ GREEN_BACK = "\033[42m"
17
+ BROWN_BACK = "\033[43m"
18
+ BLUE_BACK = "\033[44m"
19
+ MAGENTA_BACK = "\033[45m"
20
+ CYAN_BACK = "\033[46m"
21
+ WHITE_BACK = "\033[47m"
22
+
23
+ # ANSI control chars
24
+ RESET_COLORS = "\033[0m"
25
+ BOLD_ON = "\033[1m"
26
+ BLINK_ON = "\033[5m"
27
+ REVERSE_ON = "\033[7m"
28
+ BOLD_OFF = "\033[22m"
29
+ BLINK_OFF = "\033[25m"
30
+ REVERSE_OFF = "\033[27m"
31
+
32
+ end
@@ -0,0 +1,17 @@
1
+ module XBar::HasAndBelongsToManyAssociation
2
+ def self.included(base)
3
+ base.instance_eval do
4
+ alias_method_chain :insert_record, :xbar
5
+ end
6
+ end
7
+
8
+ def insert_record_with_xbar(record, force = true, validate = true)
9
+ if should_wrap_the_connection?
10
+ XBar.using(@owner.current_shard) { insert_record_without_xbar(record, force, validate) }
11
+ else
12
+ insert_record_without_xbar(record, force, validate)
13
+ end
14
+ end
15
+ end
16
+
17
+ ActiveRecord::Associations::HasAndBelongsToManyAssociation.send(:include, XBar::HasAndBelongsToManyAssociation)
@@ -0,0 +1,14 @@
1
+ require "logger"
2
+
3
+ class XBar::Logger < Logger
4
+ def format_message(severity, timestamp, progname, msg)
5
+ str = super
6
+
7
+ if ActiveRecord::Base.connection.respond_to?(:current_shard)
8
+ str += "Shard: #{ActiveRecord::Base.connection.current_shard} -"
9
+ end
10
+
11
+ str
12
+ end
13
+ end
14
+