Module: Octopus::AssociationShardTracking

Defined in:
lib/octopus/association_shard_tracking.rb

Defined Under Namespace

Modules: InstanceMethods Classes: MismatchedShards

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object


21
22
23
# File 'lib/octopus/association_shard_tracking.rb', line 21

def self.extended(base)
  base.send(:include, InstanceMethods)
end

Instance Method Details

#assign_octopus_opts(scope, options) ⇒ Object


57
58
59
60
61
62
63
# File 'lib/octopus/association_shard_tracking.rb', line 57

def assign_octopus_opts(scope, options)
  if options == {} && scope.is_a?(Hash)
    default_octopus_opts(scope)
  else
    default_octopus_opts(options)
  end
end

#default_octopus_opts(options) ⇒ Object


52
53
54
55
# File 'lib/octopus/association_shard_tracking.rb', line 52

def default_octopus_opts(options)
  options[:before_add] = [ :connection_on_association=, options[:before_add] ].compact.flatten
  options[:before_remove] = [ :connection_on_association=, options[:before_remove] ].compact.flatten
end

#has_and_belongs_to_many(association_id, scope = nil, **options, &extension) ⇒ Object


47
48
49
50
# File 'lib/octopus/association_shard_tracking.rb', line 47

def has_and_belongs_to_many(association_id, scope = nil, options = {}, &extension)
  assign_octopus_opts(scope, options)
  super
end

#has_many(name, scope = nil, **options, &extension) ⇒ Object


38
39
40
41
42
43
44
45
# File 'lib/octopus/association_shard_tracking.rb', line 38

def has_many(name, scope = nil, **options, &extension)
  if options == {} && scope.is_a?(Hash)
    default_octopus_opts(scope)
  else
    default_octopus_opts(options)
  end
  super
end