Module: Switchman::ActiveRecord::Base::ClassMethods
- Defined in:
- lib/switchman/active_record/base.rb
Instance Method Summary collapse
- #integral_id? ⇒ Boolean
- #shard_category ⇒ Object
- #shard_category=(category) ⇒ Object
- #transaction(*args) ⇒ Object
Instance Method Details
#integral_id? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/switchman/active_record/base.rb', line 28 def integral_id? if @integral_id == nil @integral_id = columns_hash[primary_key].try(:type) == :integer end @integral_id end |
#shard_category ⇒ Object
11 12 13 |
# File 'lib/switchman/active_record/base.rb', line 11 def shard_category @shard_category || :default end |
#shard_category=(category) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/switchman/active_record/base.rb', line 15 def shard_category=(category) categories = Shard.const_get(:CATEGORIES) if categories[shard_category] categories[shard_category].delete(self) categories.delete(shard_category) if categories[shard_category].empty? end connection_handler.uninitialize_ar(self) categories[category] ||= [] categories[category] << self @shard_category = category connection_handler.initialize_categories(superclass) end |
#transaction(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/switchman/active_record/base.rb', line 35 def transaction(*args) if self != ::ActiveRecord::Base && current_scope current_scope.activate do db = Shard.current(shard_category).database_server if ::Shackles.environment != db.shackles_environment db.unshackle { super } else super end end else db = Shard.current(shard_category).database_server if ::Shackles.environment != db.shackles_environment db.unshackle { super } else super end end end |