Sha256: 10fef779c304be1fd01df0dc282a3aef50fc9b0db56f2b8bc9e14cf6a03eafe5
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module Targetable extend ActiveSupport::Concern module ClassMethods def targetable true end end module TargetableModels extend self @included_in ||= [] def add(klass) @included_in << klass end def included_in @included_in end end included do has_one :mapping, as: :targetable TargetableModels.add self def targetable_attrs associated_cols = self.class.reflect_on_all_associations(:belongs_to) foreign_key_cols = associated_cols.map(&:foreign_key) meta_cols = ["updated_at", "created_at", "id"] ignored_cols = meta_cols + foreign_key_cols mappable_columns = self.attributes.keys - ignored_cols end def self.targetable_attrs associated_cols = self.reflect_on_all_associations(:belongs_to) foreign_key_cols = associated_cols.map(&:foreign_key) meta_cols = ["updated_at", "created_at", "id"] ignored_cols = meta_cols + foreign_key_cols mappable_columns = self.column_names - ignored_cols end def self.parent_models # self.reflect_on_all_associations(:belongs_to).first.class_name self.validators.map(&:attributes).flatten end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
buttafly-0.0.1 | app/concerns/targetable.rb |