Sha256: ba04b98a61dbccd953f1c3e22ee126c0f8afeab047996ee1cf2a688ced0fb143

Contents?: true

Size: 861 Bytes

Versions: 16

Compression:

Stored size: 861 Bytes

Contents

require 'roles_mongoid/strategy/shared'

class Symbol
  def admin?
    self == :admin
  end
end

module Roles::Mongoid
  module Strategy
    module Single
      include Shared            
      # assigns first valid role from list of roles
      def add_roles *role_names
        new_roles = select_valid_roles(role_names) 
        new_role = new_roles.first if !new_roles.empty?
        set_role new_role
      end

      # should remove the current single role (set = nil) 
      # only if it is contained in the list of roles to be removed
      def remove_roles *role_names
        roles = role_names.flat_uniq
        set_empty_role if roles_diff(roles).empty?
        true
      end 
      
      def roles_list
        raise 'the method #roles should be present' if !respond_to? :roles
        present_roles(roles)
      end            
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
roles_mongoid-0.4.8 lib/roles_mongoid/strategy/single.rb
roles_mongoid_zhd-0.4.8 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.7 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.6 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.5 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.4 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.3 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.2 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.1 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.4.0 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.3.6 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.3.5 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.3.4 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.3.3 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.3.2 lib/roles_mongoid/strategy/single.rb
roles_mongoid-0.3.1 lib/roles_mongoid/strategy/single.rb