module DoorMat::AttrAsymmetricStore::ClassMethods
Public Instance Methods
attr_asymmetric_store(*args, **options)
click to toggle source
# File lib/door_mat/attr_asymmetric_store.rb, line 61 def attr_asymmetric_store(*args, **options) return unless self.table_exists? actor_column = options.fetch(:actor_column, :actor).to_s unless self.attribute_names.include? "#{actor_column}_id" raise ActiveRecord::ActiveRecordError, "attr_asymmetric_store records must belong to a DoorMat::Actor but could not find the actor column. Pass the actor_column: :actor_column_name option to specify it." end args.each do |arg| column_type = (self.columns_hash[arg.to_s].cast_type.respond_to?(:type) && self.columns_hash[arg.to_s].cast_type.type) || self.columns_hash[arg.to_s].cast_type.to_s if [:text, :string].include? column_type after_find DoorMat::AttrAsymmetricStore::AttrAsymmetricStoreWrapper.new(arg.to_s, actor_column) around_save DoorMat::AttrAsymmetricStore::AttrAsymmetricStoreWrapper.new(arg.to_s, actor_column) else raise ActiveRecord::ActiveRecordError, "attr_asymmetric_store only support text and string column types." end end end