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

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

Defined Under Namespace

Classes: CodeGenerator

Instance Method Summary collapse

Instance Method Details

#sharded_column?(column_name) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
# 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.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)


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

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)


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

def sharded_primary_key?
  !(self <= UnshardedRecord) && integral_id?
end