Module: CanCanExplainer::RuleExtensions
- Defined in:
- lib/cancan_explainer/cancan_extensions.rb
Instance Method Summary collapse
-
#determine_source_location_from(caller) ⇒ Object
The source location of the rule is found in the stack trace entry immediately prior to ‘Ability#can` (or `cannot`).
- #initialize(*args) ⇒ Object
- #matches_conditions?(action, subject, extra_args) ⇒ Boolean
Instance Method Details
#determine_source_location_from(caller) ⇒ Object
The source location of the rule is found in the stack trace entry immediately prior to ‘Ability#can` (or `cannot`).
12 13 14 15 16 17 |
# File 'lib/cancan_explainer/cancan_extensions.rb', line 12 def determine_source_location_from(caller) index = caller.index { |line| line =~ %r{lib/cancan/ability\.rb:\d+:in `(can|cannot)'} } index.nil? ? nil : caller[index + 1] end |
#initialize(*args) ⇒ Object
5 6 7 8 |
# File 'lib/cancan_explainer/cancan_extensions.rb', line 5 def initialize(*args) @source_location = determine_source_location_from(caller) super end |
#matches_conditions?(action, subject, extra_args) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/cancan_explainer/cancan_extensions.rb', line 19 def matches_conditions?(action, subject, extra_args) result = super CanCanExplainer. explanation&. add_condition_match(@source_location, action, subject, extra_args) result end |