Module: Switchman::ActiveRecord::Association
- Defined in:
- lib/switchman/active_record/association.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_record_with_sharding(*args) ⇒ Object
- #load_target_with_sharding ⇒ Object
- #scoped_with_sharding ⇒ Object
- #shard ⇒ Object
Class Method Details
.included(klass) ⇒ Object
4 5 6 7 8 |
# File 'lib/switchman/active_record/association.rb', line 4 def self.included(klass) %w{build_record load_target scoped}.each do |method| klass.alias_method_chain(method, :sharding) end end |
Instance Method Details
#build_record_with_sharding(*args) ⇒ Object
19 20 21 |
# File 'lib/switchman/active_record/association.rb', line 19 def build_record_with_sharding(*args) self.shard.activate { build_record_without_sharding(*args) } end |
#load_target_with_sharding ⇒ Object
23 24 25 |
# File 'lib/switchman/active_record/association.rb', line 23 def load_target_with_sharding self.shard.activate { load_target_without_sharding } end |
#scoped_with_sharding ⇒ Object
27 28 29 30 |
# File 'lib/switchman/active_record/association.rb', line 27 def scoped_with_sharding shard_value = @reflection.[:multishard] ? @owner : self.shard self.shard.activate { scoped_without_sharding.shard(shard_value, :association) } end |
#shard ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/switchman/active_record/association.rb', line 10 def shard # polymorphic associations assume the same shard as the owning item if @reflection.[:polymorphic] || @reflection.klass.shard_category == @owner.class.shard_category @owner.shard else Shard.default end end |