Sha256: 82334b50b019065f571a06758d2f3b03d07972ad690cfff7b46f02f1a1879bd8
Contents?: true
Size: 643 Bytes
Versions: 4
Compression:
Stored size: 643 Bytes
Contents
module ActsAsUser module IsUser def self.included(base) base.belongs_to :userable, polymorphic: true base.extend ClassMethods #loads models acting as users when the hook is loaded base.define_models_acting_as_users end module ClassMethods def define_models_acting_as_users models_acting_as_users = ActsAsUser.models_acting_as_users.map(&:to_s).map(&:downcase) models_acting_as_users.each do |model_class_name| define_method("#{model_class_name}?") do self.userable_type.to_s.downcase == model_class_name end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems