Module: Octopus::Model::InstanceMethods

Includes:
SharedMethods
Defined in:
lib/octopus/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedMethods

#clean_table_name, clear_active_connections_with_octopus!, clear_all_connections_with_octopus!, connected_with_octopus?, connection_pool_with_octopus, connection_proxy, connection_with_octopus, #hijack_connection, #hijack_initializer, #set_current_shard, should_use_normal_connection?, #using

Class Method Details

.included(base) ⇒ Object



112
113
114
115
116
117
# File 'lib/octopus/model.rb', line 112

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_chain, :perform_validations, :octopus)
end

Instance Method Details

#equality_with_octopus(comparison_object) ⇒ Object



131
132
133
# File 'lib/octopus/model.rb', line 131

def equality_with_octopus(comparison_object)
  equality_without_octopus(comparison_object) && comparison_object.current_shard == current_shard
end

#perform_validations_with_octopus(*args) ⇒ Object



135
136
137
138
139
140
141
142
143
# File 'lib/octopus/model.rb', line 135

def perform_validations_with_octopus(*args)
  if Octopus.enabled? and should_set_current_shard?
    Octopus.using(self.current_shard) do
      perform_validations_without_octopus(*args)
    end
  else
    perform_validations_without_octopus(*args)
  end
end

#run_on_shard(&block) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/octopus/model.rb', line 123

def run_on_shard(&block)
  if self.current_shard
    self.class.connection_proxy.run_queries_on_shard(self.current_shard, &block)
  else
    yield
  end
end

#should_set_current_shard?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/octopus/model.rb', line 119

def should_set_current_shard?
  self.respond_to?(:current_shard) && !self.current_shard.nil?
end