Sha256: d43a8b8dc440d10ed9407a99082cc80a915e0fefd9b2d9fac4744a25a18977ca
Contents?: true
Size: 1.22 KB
Versions: 15
Compression:
Stored size: 1.22 KB
Contents
require 'roles_mongoid/strategy/single' module RoleStrategy::Mongoid module RoleString def self.default_role_attribute :role_string 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) in_any_role(role_name) end def in_any_role(*role_names) begin where(:"#{role_attribute}".in => role_names) rescue return [] end end end module Implementation include Roles::Mongoid::Strategy::Single def new_role role role = role.kind_of?(Array) ? role.first : role role.to_s end def new_roles *roles new_role roles.flatten.first end def present_role role return role if role.kind_of? Array role.split(',').map(&:to_sym) end def set_empty_role self.send("#{role_attribute}=", "") end alias_method :present_roles, :present_role end extend Roles::Generic::User::Configuration configure :num => :single end end
Version data entries
15 entries across 15 versions & 2 rubygems