module Octopus::AssociationShardTracking

Public Class Methods

extended(base) click to toggle source
# File lib/octopus/association_shard_tracking.rb, line 3
def self.extended(base)
  base.send(:include, InstanceMethods)
end

Public Instance Methods

default_octopus_opts(options) click to toggle source
# File lib/octopus/association_shard_tracking.rb, line 92
def default_octopus_opts(options)
  if options[:before_add].is_a?(Array)
    options[:before_add] << :connection_on_association=
  elsif options[:before_add].is_a?(Symbol)
    options[:before_add] = [:connection_on_association=, options[:before_add]]
  else
    options[:before_add] = :connection_on_association=
  end

  if options[:before_remove].is_a?(Array)
    options[:before_remove] << :connection_on_association=
  elsif options[:before_remove].is_a?(Symbol)
    options[:before_remove] = [:connection_on_association=, options[:before_remove]]
  else
    options[:before_remove] = :connection_on_association=
  end

  options[:extend] = [Octopus::AssociationShardTracking::QueryOnCurrentShard, options[:extend]].flatten.compact
end
has_and_belongs_to_many(association_id, scope = nil, options = {}, &extension) click to toggle source
Calls superclass method
# File lib/octopus/association_shard_tracking.rb, line 77
def has_and_belongs_to_many(association_id, scope = nil, options = {}, &extension)
  if options == {} && scope.is_a?(Hash)
    default_octopus_opts(scope)
  else
    default_octopus_opts(options)
  end
  super
end
has_many(association_id, scope = nil, options = {}, &extension) click to toggle source
Calls superclass method
# File lib/octopus/association_shard_tracking.rb, line 61
def has_many(association_id, scope = nil, options = {}, &extension)
  if options == {} && scope.is_a?(Hash)
    default_octopus_opts(scope)
  else
    default_octopus_opts(options)
  end
  super
end