Module: Switchman::ActiveRecord::Base::ClassMethods

Defined in:
lib/switchman/active_record/base.rb

Instance Method Summary collapse

Instance Method Details

#integral_id?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/switchman/active_record/base.rb', line 24

def integral_id?
  if @integral_id == nil
    @integral_id = columns_hash[primary_key].try(:type) == :integer
  end
  @integral_id
end

#reset_column_informationObject



51
52
53
54
# File 'lib/switchman/active_record/base.rb', line 51

def reset_column_information
  @sharded_column_values = {}
  super
end

#shard_categoryObject



7
8
9
# File 'lib/switchman/active_record/base.rb', line 7

def shard_category
  @shard_category || (self.superclass < ::ActiveRecord::Base && self.superclass.shard_category) || :default
end

#shard_category=(category) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/switchman/active_record/base.rb', line 11

def shard_category=(category)
  categories = Shard.const_get(:CATEGORIES)
  if categories[shard_category]
    categories[shard_category].delete(self)
    categories.delete(shard_category) if categories[shard_category].empty?
  end
  connection_handler.uninitialize_ar(self)
  categories[category] ||= []
  categories[category] << self
  @shard_category = category
  connection_handler.initialize_categories(superclass)
end

#transaction(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/switchman/active_record/base.rb', line 31

def transaction(*args)
  if self != ::ActiveRecord::Base && current_scope
    current_scope.activate do
      db = Shard.current(shard_category).database_server
      if ::Shackles.environment != db.shackles_environment
        db.unshackle { super }
      else
        super
      end
    end
  else
    db = Shard.current(shard_category).database_server
    if ::Shackles.environment != db.shackles_environment
      db.unshackle { super }
    else
      super
    end
  end
end

#unscopedObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/switchman/active_record/base.rb', line 56

def unscoped
  if block_given?
    super do
      current_scope.shard_value = nil
      yield
    end
  else
    result = super
    result.shard_value = nil
    result
  end
end