Module: OnlineMigrations::ShardAware
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/online_migrations/shard_aware.rb
Instance Method Summary collapse
- #connection_class ⇒ Object
- #connection_class_name=(value) ⇒ Object
- #on_shard_if_present(&block) ⇒ Object
Instance Method Details
#connection_class ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/online_migrations/shard_aware.rb', line 31 def connection_class if connection_class_name && (klass = connection_class_name.safe_constantize) Utils.find_connection_class(klass) else ActiveRecord::Base end end |
#connection_class_name=(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/online_migrations/shard_aware.rb', line 19 def connection_class_name=(value) if value && (klass = value.safe_constantize) if !(klass <= ActiveRecord::Base) raise ArgumentError, "connection_class_name is not an ActiveRecord::Base child class" end connection_class = Utils.find_connection_class(klass) super(connection_class.name) end end |
#on_shard_if_present(&block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/online_migrations/shard_aware.rb', line 11 def on_shard_if_present(&block) if shard connection_class.connected_to(shard: shard.to_sym, role: :writing, &block) else yield end end |