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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/xbar/model.rb', line 105 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
97 98 99 100 101 102 103 |
# File 'lib/xbar/model.rb', line 97 def if should_use_normal_connection? else connection_proxy.connection_pool end end |
#connection_proxy ⇒ Object
80 81 82 83 |
# File 'lib/xbar/model.rb', line 80 def connection_proxy puts "Model allocating new connection proxy" unless Thread.current[:connection_proxy] Thread.current[:connection_proxy] ||= XBar::Proxy.new end |
#connection_with_xbar ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/xbar/model.rb', line 85 def if should_use_normal_connection? else #puts "Model connection with octopus" if XBar.debug #if (connection_proxy.current_model.nil?) || (self != ActiveRecord::Base) connection_proxy.current_model = self #end connection_proxy end end |
#should_use_normal_connection? ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/xbar/model.rb', line 69 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
138 139 140 141 142 143 144 |
# File 'lib/xbar/model.rb', line 138 def unreplicated_model if XBar.rails32? self._unreplicated = true else write_inheritable_attribute(:_unreplicated, true) end end |
#unreplicated_model? ⇒ Boolean
146 147 148 149 150 151 152 |
# File 'lib/xbar/model.rb', line 146 def unreplicated_model? if XBar.rails32? _unreplicated else read_inheritable_attribute(:_unreplicated) end end |
#using(shard_name) ⇒ Object
123 124 125 126 127 |
# File 'lib/xbar/model.rb', line 123 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
129 130 131 132 133 134 135 136 |
# File 'lib/xbar/model.rb', line 129 def using_any(shard_name = nil) connection_proxy.slave_read_allowed = true if shard_name using(shard_name) else self end end |