Massive role checking via User#any_role? & Role#any?

@the-teacher the-teacher released this Aug 1, 2013 · 146 commits to master since this release

Massive role checking via User#any_role? & Role#any?

TheRole 2.1.0 provide following methods User#any_role? and Role#any? for massive checking of user's roles.

Now you can write following code:

  - if @user.any_role?(posts: :manage, pages: :manage)
      %h4 Publications:
      %ul
        - if @user.has_role?(:posts, :manage)
          %li= link_to 'My Posts', manage_user_posts_url(@user)

        - if @user.has_role?(:pages, :manage)
          %li= link_to 'My Pages', manage_user_pages_url(@user)

instead:

  - if @user.has_role?(:posts, :manage) || @user.has_role?(:pages, :manage)
      %h4 Publications:
      %ul
        - if @user.has_role?(:posts, :manage)
          %li= link_to 'My Posts', manage_user_posts_url(@user)

        - if @user.has_role?(:pages, :manage)
          %li= link_to 'My Pages', manage_user_pages_url(@user)

I hope it's will be usefull not only for me.

Have a nice day!

Downloads