Module: ActiveRecordShards::Model
- Defined in:
- lib/active_record_shards/model.rb
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#is_sharded? ⇒ Boolean
rubocop:disable Style/PredicateName.
- #not_sharded ⇒ Object
- #on_slave_by_default=(val) ⇒ Object
- #on_slave_by_default? ⇒ Boolean
Class Method Details
.extended(base) ⇒ Object
54 55 56 57 |
# File 'lib/active_record_shards/model.rb', line 54 def self.extended(base) base.send(:include, InstanceMethods) base.after_initialize :initialize_shard_and_slave end |
Instance Method Details
#is_sharded? ⇒ Boolean
rubocop:disable Style/PredicateName
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/active_record_shards/model.rb', line 11 def is_sharded? # rubocop:disable Style/PredicateName if self == ActiveRecord::Base @sharded != false && supports_sharding? elsif self == base_class if @sharded.nil? ActiveRecord::Base.is_sharded? else @sharded != false end else base_class.is_sharded? end end |
#not_sharded ⇒ Object
4 5 6 7 8 9 |
# File 'lib/active_record_shards/model.rb', line 4 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
35 36 37 |
# File 'lib/active_record_shards/model.rb', line 35 def on_slave_by_default=(val) @on_slave_by_default = val end |
#on_slave_by_default? ⇒ Boolean
25 26 27 28 29 30 31 32 33 |
# File 'lib/active_record_shards/model.rb', line 25 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 |