Class: SubjectClassMatcher
- Inherits:
-
Object
- Object
- SubjectClassMatcher
- Defined in:
- lib/cancan/class_matcher.rb
Overview
This class is responsible for matching classes and their subclasses as well as upmatching classes to their ancestors. This is used to generate sti connections
Class Method Summary collapse
- .matches_class_or_is_related(subject, sub) ⇒ Object
- .matches_subject_class?(subjects, subject) ⇒ Boolean
- .matching_class_check(subject, sub, has_subclasses) ⇒ Object
Class Method Details
.matches_class_or_is_related(subject, sub) ⇒ Object
25 26 27 28 29 |
# File 'lib/cancan/class_matcher.rb', line 25 def self.(subject, 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 |
.matches_subject_class?(subjects, subject) ⇒ Boolean
7 8 9 10 11 12 |
# File 'lib/cancan/class_matcher.rb', line 7 def self.matches_subject_class?(subjects, subject) subjects.any? do |sub| has_subclasses = subject.respond_to?(:subclasses) matching_class_check(subject, sub, has_subclasses) end end |
.matching_class_check(subject, sub, has_subclasses) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cancan/class_matcher.rb', line 14 def self.matching_class_check(subject, sub, has_subclasses) matches = (subject, sub) if has_subclasses return matches unless StiDetector.sti_class?(sub) matches || subject.subclasses.include?(sub) else matches end end |