Class: CanCanExplainer::Explanation

Inherits:
Object
  • Object
show all
Defined in:
lib/cancan_explainer/explanation.rb

Instance Method Summary collapse

Constructor Details

#initializeExplanation

Returns a new instance of Explanation.



3
4
5
# File 'lib/cancan_explainer/explanation.rb', line 3

def initialize
  @conditions_matched = []
end

Instance Method Details

#add_condition_match(source_location, action, subject, extra_args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/cancan_explainer/explanation.rb', line 7

def add_condition_match(source_location, action, subject, extra_args)
  @conditions_matched.push(
    {
      source_location: source_location,
      action: action,
      subject: subject,
      extra_args: extra_args
    }
  )
end

#to_sObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cancan_explainer/explanation.rb', line 18

def to_s
  @conditions_matched.map { |e|
    format(
      "%s %s %s %s",
      e[:action],
      e[:subject],
      e[:extra_args],
      e[:source_location]
    )
  }.join("\n")
end