Sha256: 2b42f631ebe30d889ae9dfd707eedac52f648e8c7361cc0ba9d0531996704a7e

Contents?: true

Size: 958 Bytes

Versions: 22

Compression:

Stored size: 958 Bytes

Contents

module SimpleRoles
  module ClassMethods 
  
    def is_role_in_group?(role, group)
      raise "No group #{group} defined in User model" if !role_groups.has_key?(group)
      role_groups[group].include?(role) 
    end
  
    def role_groups
      {:bloggers => [:editor]} 
    end

    def roles
      [:guest, :user, :admin, :editor]
    end
  end

  module InstanceMethods

    attr_accessor :role
    attr_accessor :role_groups_list

    def has_role? rolle
      roles_list.include? rolle
    end

    def has_any_role? roles
      roles.include?(role.to_sym)
    end

    def roles_list
      role.to_s.scan(/\w+/).map{|r| r.to_sym}
    end

    def is_in_group? group
      role_groups_list.include? group
    end
    alias_method :in_role_group?, :is_in_group?

    def role_groups_list
      return role_groups.scan(/\w+/).map(&:to_sym) if respond_to?(:role_groups) && !role_groups.nil?
      @role_groups_list || [] #[:bloggers]
    end
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
cantango-0.9.4.7 spec/simple_roles.rb
cantango-0.9.4.6 spec/simple_roles.rb
cantango-0.9.4.5 spec/simple_roles.rb
cantango-0.9.4.3 spec/simple_roles.rb
cantango-0.9.4.2 spec/simple_roles.rb
cantango-0.9.4.1 spec/simple_roles.rb
cantango-0.9.4 spec/simple_roles.rb
cantango-0.9.3.2 spec/simple_roles.rb
cantango-0.8.9.5 spec/simple_roles.rb
cantango-0.8.9.4 spec/simple_roles.rb
cantango-0.8.9.3 spec/simple_roles.rb
cantango-0.8.9.2 spec/simple_roles.rb
cantango-0.8.9.1 spec/simple_roles.rb
cantango-0.8.9 spec/simple_roles.rb
cantango-0.8.8.1 spec/simple_roles.rb
cantango-0.8.8 spec/simple_roles.rb
cantango-0.8.7 spec/simple_roles.rb
cantango-0.8.6.2 spec/simple_roles.rb
cantango-0.8.6.1 spec/simple_roles.rb
cantango-0.8.6 spec/simple_roles.rb