module Octopus::Model::ClassMethods
Attributes
custom_octopus_table_name[RW]
Public Class Methods
extended(base)
click to toggle source
# File lib/octopus/model.rb, line 85 def self.extended(base) base.class_attribute(:replicated) base.class_attribute(:sharded) base.class_attribute(:allowed_shards) base.hijack_methods end
table_name=(value = nil)
click to toggle source
Calls superclass method
# File lib/octopus/model.rb, line 122 def table_name=(value = nil) self.custom_octopus_table_name = true super end
Public Instance Methods
allow_shard(*shards)
click to toggle source
# File lib/octopus/model.rb, line 100 def allow_shard(*shards) self.allowed_shards ||= [] self.allowed_shards += shards end
allowed_shard?(shard)
click to toggle source
# File lib/octopus/model.rb, line 143 def allowed_shard?(shard) if custom_octopus_connection allowed_shards && shard && allowed_shards.include?(shard) else true end end
clear_active_connections_with_octopus!()
click to toggle source
# File lib/octopus/model.rb, line 168 def clear_active_connections_with_octopus! if should_use_normal_connection? clear_active_connections_without_octopus! else connection_proxy.clear_active_connections! end end
clear_all_connections_with_octopus!()
click to toggle source
# File lib/octopus/model.rb, line 176 def clear_all_connections_with_octopus! if should_use_normal_connection? clear_all_connections_without_octopus! else connection_proxy.clear_all_connections! end end
connected_with_octopus?()
click to toggle source
# File lib/octopus/model.rb, line 184 def connected_with_octopus? if should_use_normal_connection? connected_without_octopus? else connection_proxy.connected? end end
connection_pool_with_octopus()
click to toggle source
# File lib/octopus/model.rb, line 160 def connection_pool_with_octopus if should_use_normal_connection? connection_pool_without_octopus else connection_proxy.connection_pool end end
connection_proxy()
click to toggle source
# File lib/octopus/model.rb, line 129 def connection_proxy ActiveRecord::Base.class_variable_defined?(:@@connection_proxy) && ActiveRecord::Base.class_variable_get(:@@connection_proxy) || ActiveRecord::Base.class_variable_set(:@@connection_proxy, Octopus::Proxy.new) end
connection_with_octopus()
click to toggle source
# File lib/octopus/model.rb, line 151 def connection_with_octopus if should_use_normal_connection? connection_without_octopus else connection_proxy.current_model = self connection_proxy end end
hijack_methods()
click to toggle source
# File lib/octopus/model.rb, line 105 def hijack_methods around_save :run_on_shard, :unless => lambda { self.class.custom_octopus_connection } after_initialize :set_current_shard class_attribute :custom_octopus_connection class << self attr_accessor :custom_octopus_table_name alias_method_chain :connection, :octopus alias_method_chain :connection_pool, :octopus alias_method_chain :clear_all_connections!, :octopus alias_method_chain :clear_active_connections!, :octopus alias_method_chain :connected?, :octopus alias_method_chain(:set_table_name, :octopus) if Octopus.rails3? def table_name=(value = nil) self.custom_octopus_table_name = true super end end end
octopus_establish_connection(spec = ENV['DATABASE_URL'])
click to toggle source
# File lib/octopus/model.rb, line 197 def octopus_establish_connection(spec = ENV['DATABASE_URL']) self.custom_octopus_connection = true if spec establish_connection(spec) end
octopus_set_table_name(value = nil)
click to toggle source
# File lib/octopus/model.rb, line 202 def octopus_set_table_name(value = nil) ActiveSupport::Deprecation.warn 'Calling `octopus_set_table_name` is deprecated and will be removed in Octopus 1.0.', caller set_table_name(value) end
replicated_model()
click to toggle source
# File lib/octopus/model.rb, line 92 def replicated_model self.replicated = true end
set_table_name_with_octopus(value = nil, &block)
click to toggle source
# File lib/octopus/model.rb, line 192 def set_table_name_with_octopus(value = nil, &block) self.custom_octopus_table_name = true set_table_name_without_octopus(value, &block) end
sharded_model()
click to toggle source
# File lib/octopus/model.rb, line 96 def sharded_model self.sharded = true end
should_use_normal_connection?()
click to toggle source
# File lib/octopus/model.rb, line 135 def should_use_normal_connection? if !Octopus.enabled? true elsif custom_octopus_connection !connection_proxy.block || !allowed_shard?(connection_proxy.current_shard) end end