Sha256: a59c167f0984c5415a54e7de57bdae4ecf4ec5c306d05afb317e732a9c125749
Contents?: true
Size: 1.35 KB
Versions: 6
Compression:
Stored size: 1.35 KB
Contents
# adding vulgata_user method to all active record classes class ActiveRecord::Base def self.vulgata_user(options = {}) has_one :vulgata_role_object, class_name: "Vulgata::UserRole", as: :user has_many :vulgata_locale_objects, class_name: "Vulgata::UserLocale", as: :user def vulgata_role if self.vulgata_role_object && self.vulgata_role_object.role return self.vulgata_role_object.role.to_sym end nil end def vulgata_role=(role) if role.nil? self.vulgata_role_object.destroy else self.vulgata_role_object = Vulgata::UserRole.new unless self.vulgata_role_object self.vulgata_role_object.role = role self.vulgata_role_object.save end end def vulgata_locales if self.vulgata_locale_objects return self.vulgata_locale_objects.map { |o| o.locale.to_sym } end nil end def vulgata_locales=(locales) self.vulgata_locale_objects.each do |o| o.destroy end locales.each do |locale| self.vulgata_locale_objects << Vulgata::UserLocale.new(user: self, locale: locale) end end def vulgata_admin? vulgata_role == :admin end def vulgata_proofreader? vulgata_role == :proofreader end def vulgata_translator? vulgata_role == :translator end end end
Version data entries
6 entries across 6 versions & 1 rubygems