Module: Switchman::ActiveRecord::AttributeMethods::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#sharded_column?(column_name) ⇒ Boolean

Returns:

  • (Boolean)


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

def sharded_column?(column_name)
  column_name = column_name.to_s
  @sharded_column_values ||= {}
  unless @sharded_column_values.has_key?(column_name)
    @sharded_column_values[column_name] = (column_name == primary_key && sharded_primary_key?) || sharded_foreign_key?(column_name)
  end
  @sharded_column_values[column_name]
end

#sharded_foreign_key?(column_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/switchman/active_record/attribute_methods.rb', line 12

def sharded_foreign_key?(column_name)
  reflection = reflection_for_integer_attribute(column_name.to_s)
  return false unless reflection
  reflection.options[:polymorphic] || reflection.klass.sharded_primary_key?
end

#sharded_primary_key?Boolean

Returns:

  • (Boolean)


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

def sharded_primary_key?
  self != Shard && shard_category != :unsharded && integral_id?
end