Sha256: c8957ad1c57c25b7fc89c670bcf25699a6d0020bd8dead4a3f707be916df88f1

Contents?: true

Size: 892 Bytes

Versions: 22

Compression:

Stored size: 892 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_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

    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/dummy/config/initializers/simple_roles.rb
cantango-0.9.4.6 spec/dummy/config/initializers/simple_roles.rb
cantango-0.9.4.5 spec/dummy/config/initializers/simple_roles.rb
cantango-0.9.4.3 spec/dummy/config/initializers/simple_roles.rb
cantango-0.9.4.2 spec/dummy/config/initializers/simple_roles.rb
cantango-0.9.4.1 spec/dummy/config/initializers/simple_roles.rb
cantango-0.9.4 spec/dummy/config/initializers/simple_roles.rb
cantango-0.9.3.2 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.9.5 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.9.4 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.9.3 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.9.2 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.9.1 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.9 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.8.1 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.8 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.7 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.6.2 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.6.1 spec/dummy/config/initializers/simple_roles.rb
cantango-0.8.6 spec/dummy/config/initializers/simple_roles.rb