Module: XBar::Model::ClassMethods
- Defined in:
- lib/xbar/model.rb
Instance Method Summary collapse
- #clean_table_name ⇒ Object
- #connection_pool_with_xbar ⇒ Object
- #connection_proxy ⇒ Object
- #connection_with_xbar ⇒ Object
- #should_use_normal_connection? ⇒ Boolean
- #unreplicated_model ⇒ Object
- #unreplicated_model? ⇒ Boolean
- #using(shard_name) ⇒ Object
- #using_any(shard_name = nil) ⇒ Object
- #xbar_establish_connection(spec = nil) ⇒ Object
- #xbar_set_table_name(value = nil) ⇒ Object
Instance Method Details
#clean_table_name ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/xbar/model.rb', line 96 def clean_table_name return unless connection_proxy.should_clean_table_name? if self != ActiveRecord::Base && self.respond_to?(:reset_table_name) && (if XBar.rails32? !self._reset_table_name else !self.read_inheritable_attribute(:_reset_table_name) end ) self.reset_table_name end if XBar.rails3? self.reset_column_information self.instance_variable_set(:@quoted_table_name, nil) end end |
#connection_pool_with_xbar ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/xbar/model.rb', line 88 def if should_use_normal_connection? else connection_proxy.connection_pool end end |
#connection_proxy ⇒ Object
75 76 77 |
# File 'lib/xbar/model.rb', line 75 def connection_proxy Thread.current[:connection_proxy] ||= XBar::Proxy.new end |
#connection_with_xbar ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/xbar/model.rb', line 79 def if should_use_normal_connection? else connection_proxy.current_model = self connection_proxy end end |
#should_use_normal_connection? ⇒ Boolean
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/xbar/model.rb', line 64 def should_use_normal_connection? (defined?(Rails) && XBar.config && !XBar.environments.include?(Rails.env.to_s)) || (if XBar.rails32? _establish_connection else self.read_inheritable_attribute(:_establish_connection) end ) end |
#unreplicated_model ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/xbar/model.rb', line 129 def unreplicated_model if XBar.rails32? self._unreplicated = true else write_inheritable_attribute(:_unreplicated, true) end end |
#unreplicated_model? ⇒ Boolean
137 138 139 140 141 142 143 |
# File 'lib/xbar/model.rb', line 137 def unreplicated_model? if XBar.rails32? _unreplicated else read_inheritable_attribute(:_unreplicated) end end |
#using(shard_name) ⇒ Object
114 115 116 117 118 |
# File 'lib/xbar/model.rb', line 114 def using(shard_name) return self if defined?(::Rails) && !XBar.environments.include?(Rails.env.to_s) clean_table_name return XBar::ScopeProxy.new(shard_name, self) end |
#using_any(shard_name = nil) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/xbar/model.rb', line 120 def using_any(shard_name = nil) connection_proxy.slave_read_allowed = true if shard_name using(shard_name) else self end end |