module Octopus::Model::InstanceMethods
Public Class Methods
included(base)
click to toggle source
# File lib/octopus/model.rb, line 32 def self.included(base) base.send(:alias_method, :equality_without_octopus, :==) base.send(:alias_method, :==, :equality_with_octopus) base.send(:alias_method, :eql?, :==) base.send(:alias_method, :perform_validations_without_octopus, :perform_validations) base.send(:alias_method, :perform_validations, :perform_validations_with_octopus) end
Public Instance Methods
equality_with_octopus(comparison_object)
click to toggle source
# File lib/octopus/model.rb, line 72 def equality_with_octopus(comparison_object) equality_without_octopus(comparison_object) && comparison_object.current_shard.to_s == current_shard.to_s end
init_with(coder)
click to toggle source
Calls superclass method
# File lib/octopus/model.rb, line 46 def init_with(coder) obj = super return obj if obj.class.connection_proxy.current_model_replicated? current_shard_value = if Octopus.rails40? || Octopus.rails41_only? coder['attributes']['current_shard'] if coder['attributes']['current_shard'].present? else coder['attributes']['current_shard'].value if coder['attributes']['current_shard'].present? && coder['attributes']['current_shard'].value.present? end if Octopus.rails40? || Octopus.rails41_only? coder['attributes'].delete('current_shard') else coder['attributes'].send(:attributes).send(:values).delete('current_shard') coder['attributes'].send(:attributes).send(:delegate_hash).delete('current_shard') end obj.current_shard = current_shard_value if current_shard_value.present? obj end
perform_validations_with_octopus(*args)
click to toggle source
# File lib/octopus/model.rb, line 76 def perform_validations_with_octopus(*args) if Octopus.enabled? && should_set_current_shard? Octopus.using(current_shard) do perform_validations_without_octopus(*args) end else perform_validations_without_octopus(*args) end end
set_current_shard()
click to toggle source
# File lib/octopus/model.rb, line 40 def set_current_shard return unless Octopus.enabled? shard = self.class.connection_proxy.current_shard self.current_shard = shard if self.class.allowed_shard?(shard) end
should_set_current_shard?()
click to toggle source
# File lib/octopus/model.rb, line 68 def should_set_current_shard? self.respond_to?(:current_shard) && !current_shard.nil? end