Sha256: e2d489654fd77c6036392e2a2017c81d9ff10718eda8a7f8c739c13270ab6f74
Contents?: true
Size: 898 Bytes
Versions: 6
Compression:
Stored size: 898 Bytes
Contents
class Role < AbstractAdapter belongs_to :user belongs_to :ownable, polymorphic: true validates_uniqueness_of :user_id, scope: [:ownable_type,:ownable_id], unless: "user_id.nil?", message: "user has already been assigned that role" validates_inclusion_of :ownable_type, in: ['SuperUser', 'Company', 'Project'] delegate :email, to: :user, allow_nil: true def attributes super.merge(email: email) end def ownable # return the SuperUser null object ownable_type == 'SuperUser' ? SuperUser.new : super end def self.ownable_assign_options(_model=nil) ([SuperUser.new] + Company.all + Project.all).map { |i| [ "#{i.class}: #{i.name}", "#{i.class}-#{i.id}"] } end def ownable_assign ownable.present? ? "#{ownable_type}-#{ownable_id}" : nil end def ownable_assign=(value) self.ownable_type,self.ownable_id = value.split('-') end end
Version data entries
6 entries across 6 versions & 1 rubygems