-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix breaking change introduced in #204 * Fix Co-authored-by: Fumiaki MATSUSHIMA <mtsmfm@gmail.com>
- Loading branch information
Showing
4 changed files
with
72 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module CanCan | ||
module Relevant | ||
# Matches both the action, subject, and attribute, not necessarily the conditions | ||
def relevant?(action, subject) | ||
subject = subject.values.first if subject.class == Hash | ||
@match_all || (matches_action?(action) && matches_subject?(subject)) | ||
end | ||
|
||
private | ||
|
||
def matches_action?(action) | ||
@expanded_actions.include?(:manage) || @expanded_actions.include?(action) | ||
end | ||
|
||
def matches_subject?(subject) | ||
@subjects.include?(:all) || @subjects.include?(subject) || matches_subject_class?(subject) | ||
end | ||
|
||
def matches_subject_class?(subject) | ||
@subjects.any? do |sub| | ||
sub.is_a?(Module) && (subject.is_a?(sub) || | ||
subject.class.to_s == sub.to_s || | ||
(subject.is_a?(Module) && subject.ancestors.include?(sub))) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters