Module: Octopus::AssociationShardTracking

Defined in:
lib/octopus/association_shard_tracking.rb

Defined Under Namespace

Modules: InstanceMethods, QueryOnCurrentShard

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



3
4
5
# File 'lib/octopus/association_shard_tracking.rb', line 3

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

Instance Method Details

#default_octopus_opts(options) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/octopus/association_shard_tracking.rb', line 82

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, options = {}, &extension) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/octopus/association_shard_tracking.rb', line 67

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, options = {}, &extension) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/octopus/association_shard_tracking.rb', line 51

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