Sha256: 28a3fb0ac5cc9a086a5340169ab7c74a098923efc45c9a29979863394093c1f9

Contents?: true

Size: 575 Bytes

Versions: 12

Compression:

Stored size: 575 Bytes

Contents

module Roles::Base
  def valid_roles_are(*role_list)
    strategy_class.valid_roles = role_list.to_symbols
  end
end

class Role
  include Mongoid::Document
  field :name, :type => String
  
  validates_uniqueness_of :name  

  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

12 entries across 12 versions & 3 rubygems

Version Path
roles_mongoid-0.4.8 lib/roles_mongoid/embedded_role.rb
mongoid_roles_zhd-0.1 lib/mongoid_roles/embedded_role.rb
roles_mongoid_zhd-0.4.8.1 lib/roles_mongoid/embedded_role.rb
roles_mongoid_zhd-0.4.8 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.7 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.6 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.5 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.4 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.3 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.2 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.1 lib/roles_mongoid/embedded_role.rb
roles_mongoid-0.4.0 lib/roles_mongoid/embedded_role.rb