Sha256: 843d66ed776ad59a12cc0e1294a838a5f5f9a5e902147ae1d92f0ef7ec484e35

Contents?: true

Size: 872 Bytes

Versions: 19

Compression:

Stored size: 872 Bytes

Contents

require 'roles_active_record/strategy/shared'

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

module Roles::ActiveRecord
  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

19 entries across 19 versions & 1 rubygems

Version Path
roles_active_record-0.4.8 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.7 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.6.4 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.6.3 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.6.2 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.6.1 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.6 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.5 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.4 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.3 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.2 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.1 lib/roles_active_record/strategy/single.rb
roles_active_record-0.4.0 lib/roles_active_record/strategy/single.rb
roles_active_record-0.3.6 lib/roles_active_record/strategy/single.rb
roles_active_record-0.3.5 lib/roles_active_record/strategy/single.rb
roles_active_record-0.3.4 lib/roles_active_record/strategy/single.rb
roles_active_record-0.3.3 lib/roles_active_record/strategy/single.rb
roles_active_record-0.3.2 lib/roles_active_record/strategy/single.rb
roles_active_record-0.3.1 lib/roles_active_record/strategy/single.rb