Module: Switchman::ActiveRecord::AttributeMethods::ClassMethods
- Defined in:
- lib/switchman/active_record/attribute_methods.rb
Instance Method Summary collapse
- #sharded_column?(column_name) ⇒ Boolean
- #sharded_foreign_key?(column_name) ⇒ Boolean
- #sharded_primary_key? ⇒ Boolean
Instance Method Details
#sharded_column?(column_name) ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/switchman/active_record/attribute_methods.rb', line 16 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
10 11 12 13 14 |
# File 'lib/switchman/active_record/attribute_methods.rb', line 10 def sharded_foreign_key?(column_name) reflection = reflection_for_integer_attribute(column_name.to_s) return false unless reflection reflection.[:polymorphic] || reflection.klass.sharded_primary_key? end |
#sharded_primary_key? ⇒ Boolean
6 7 8 |
# File 'lib/switchman/active_record/attribute_methods.rb', line 6 def sharded_primary_key? self != Shard && shard_category != :unsharded && integral_id? end |