Sha256: ae5cdccf936ec2275f4c69c02dd08e349d21d346f8f9e5ea53314056c0949796
Contents?: true
Size: 993 Bytes
Versions: 130
Compression:
Stored size: 993 Bytes
Contents
# Concern that can be used when dealing with Legacy code. # # It automatically aliases `canvas_id` -> `canvas_<model>_id` or vice-versa. module CanvasSync::Concerns module LegacyColumns extend ActiveSupport::Concern class_methods do def inherited(subclass) super.tap do legacy_column_apply(subclass) end end private def legacy_column_apply(cls) return if cls.abstract_class cid_column = "canvas_#{cls.name.downcase}_id" column_names = cls.columns.map(&:name) return if column_names.include?('canvas_id') && column_names.include?(cid_column) if column_names.include?('canvas_id') cls.alias_attribute(cid_column.to_sym, :canvas_id) elsif column_names.include?(cid_column) cls.alias_attribute(:canvas_id, cid_column.to_sym) end rescue ActiveRecord::StatementInvalid end end included do legacy_column_apply(self) end end end
Version data entries
130 entries across 130 versions & 1 rubygems