Sha256: c665cba3cf1e5307e1db4d3d5c56ddbda4a37e0bdaedcd09c7edc810755a81f6
Contents?: true
Size: 1.23 KB
Versions: 21
Compression:
Stored size: 1.23 KB
Contents
require 'roles_active_record/strategy/single' module RoleStrategy::ActiveRecord module AdminFlag def self.default_role_attribute :admin_flag end def self.included base base.extend ClassMethods end module ClassMethods def role_attribute strategy_class.roles_attribute_name.to_sym end def in_role(role_name) case role_name.downcase.to_sym when :admin where(role_attribute => true) else where(role_attribute => false) end end end module Implementation include Roles::ActiveRecord::Strategy::Single def new_role role role = role.kind_of?(Array) ? role.flatten.first : role role.admin? end def get_role self.send(role_attribute) ? strategy_class.admin_role_key : strategy_class.default_role_key end def present_roles *roles roles = roles.flat_uniq roles.map{|role| role ? :admin : :guest} end def set_empty_role self.send("#{role_attribute}=", false) end end # Implementation extend Roles::Generic::User::Configuration configure :num => :single end end
Version data entries
21 entries across 21 versions & 1 rubygems