Module: ActiveRecordShards::Model
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/active_record_shards/model.rb
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
- #is_sharded? ⇒ Boolean
- #not_sharded ⇒ Object
- #on_slave_by_default=(val) ⇒ Object
- #on_slave_by_default? ⇒ Boolean
Class Method Details
.extended(base) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_record_shards/model.rb', line 50 def self.extended(base) base.send(:include, InstanceMethods) if ActiveRecord::VERSION::MAJOR >= 3 base.after_initialize :after_initialize_with_slave else if base.method_defined?(:after_initialize) base.alias_method_chain :after_initialize, :slave else base.send(:alias_method, :after_initialize, :after_initialize_with_slave) end end end |
Instance Method Details
#is_sharded? ⇒ Boolean
10 11 12 13 14 15 16 17 18 |
# File 'lib/active_record_shards/model.rb', line 10 def is_sharded? if self == ActiveRecord::Base true elsif self == base_class @sharded != false else base_class.is_sharded? end end |
#not_sharded ⇒ Object
3 4 5 6 7 8 |
# File 'lib/active_record_shards/model.rb', line 3 def not_sharded if self == ActiveRecord::Base || self != base_class raise "You should only call not_sharded on direct descendants of ActiveRecord::Base" end @sharded = false end |
#on_slave_by_default=(val) ⇒ Object
30 31 32 |
# File 'lib/active_record_shards/model.rb', line 30 def on_slave_by_default=(val) @on_slave_by_default = val end |
#on_slave_by_default? ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'lib/active_record_shards/model.rb', line 20 def on_slave_by_default? if self == ActiveRecord::Base false elsif self == base_class @on_slave_by_default else base_class.on_slave_by_default? end end |