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

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

Instance Method Summary collapse

Instance Method Details

#find_ids_in_ranges(opts = {}, &block) ⇒ Object



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

def find_ids_in_ranges(opts={}, &block)
  opts.reverse_merge!(:loose => true)
  all.find_ids_in_ranges(opts, &block)
end

#integral_id?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/switchman/active_record/base.rb', line 27

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

#reset_column_informationObject



54
55
56
57
# File 'lib/switchman/active_record/base.rb', line 54

def reset_column_information
  @sharded_column_values = {}
  super
end

#shard_categoryObject



12
13
14
# File 'lib/switchman/active_record/base.rb', line 12

def shard_category
  connection_specification_name.to_sym
end

#shard_category=(category) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/switchman/active_record/base.rb', line 16

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
  categories[category] ||= []
  categories[category] << self
  self.connection_specification_name = category.to_s
end

#transaction(*args) ⇒ Object



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

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



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/switchman/active_record/base.rb', line 59

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