Sha256: a948005acaa032362b55b7862c2d6a9ff9062fa8ee0a430ac50b6360da20fae1
Contents?: true
Size: 763 Bytes
Versions: 4
Compression:
Stored size: 763 Bytes
Contents
module Roles::Base def valid_roles_are(*role_list) strategy_class.valid_roles = role_list.to_symbols if role_class_name role_list.each do |name| role_class_name.create(:name => name.to_s) end end end end class Role include Mongoid::Document field :name, :type => String # references_many :users # references_many :users, :class_name => 'User', :stored_as => :array class << self def find_roles(*role_names) where(:name.in => role_names.flatten).to_a end def find_role role_name raise ArgumentError, "#find_role takes a single role name as argument, not: #{role_name.inspect}" if !role_name.kind_of_label? res = find_roles(role_name) res ? res.first : res end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
roles_mongoid-0.3.4 | lib/roles_mongoid/role.rb |
roles_mongoid-0.3.3 | lib/roles_mongoid/role.rb |
roles_mongoid-0.3.2 | lib/roles_mongoid/role.rb |
roles_mongoid-0.3.1 | lib/roles_mongoid/role.rb |