Class: WhoopsNotifier::Strategy
- Inherits:
-
Object
- Object
- WhoopsNotifier::Strategy
- Defined in:
- lib/whoops_notifier/strategy.rb
Instance Attribute Summary collapse
-
#ignore_criteria ⇒ Object
ask witnesses for data, create a report using a strategy, send or ignore.
-
#name ⇒ Object
ask witnesses for data, create a report using a strategy, send or ignore.
-
#report_modifiers ⇒ Object
ask witnesses for data, create a report using a strategy, send or ignore.
Instance Method Summary collapse
-
#add_ignore_case(name, &block) ⇒ Object
block takes one param, the investigator’s report.
-
#add_report_modifier(name, &block) ⇒ Object
block should take one param, the investigator use evidence to build the report.
- #call(investigator) ⇒ Object
- #give_name(name, block) ⇒ Object
-
#initialize(name) ⇒ Strategy
constructor
A new instance of Strategy.
- #inspect ⇒ Object
Constructor Details
#initialize(name) ⇒ Strategy
Returns a new instance of Strategy.
6 7 8 9 10 11 |
# File 'lib/whoops_notifier/strategy.rb', line 6 def initialize(name) self.name = name self.ignore_criteria = [] self.report_modifiers = [] WhoopsNotifier.strategies[name] = self end |
Instance Attribute Details
#ignore_criteria ⇒ Object
ask witnesses for data, create a report using a strategy, send or ignore
4 5 6 |
# File 'lib/whoops_notifier/strategy.rb', line 4 def ignore_criteria @ignore_criteria end |
#name ⇒ Object
ask witnesses for data, create a report using a strategy, send or ignore
4 5 6 |
# File 'lib/whoops_notifier/strategy.rb', line 4 def name @name end |
#report_modifiers ⇒ Object
ask witnesses for data, create a report using a strategy, send or ignore
4 5 6 |
# File 'lib/whoops_notifier/strategy.rb', line 4 def report_modifiers @report_modifiers end |
Instance Method Details
#add_ignore_case(name, &block) ⇒ Object
block takes one param, the investigator’s report
34 35 36 37 |
# File 'lib/whoops_notifier/strategy.rb', line 34 def add_ignore_case(name, &block) give_name(name, block) @ignore_criteria << block end |
#add_report_modifier(name, &block) ⇒ Object
block should take one param, the investigator use evidence to build the report
28 29 30 31 |
# File 'lib/whoops_notifier/strategy.rb', line 28 def add_report_modifier(name, &block) give_name(name, block) @report_modifiers << block end |
#call(investigator) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/whoops_notifier/strategy.rb', line 13 def call(investigator) report_modifiers.each do |report_modifier| report_modifier.call(investigator.report, investigator.evidence) end ignore_criteria.each do |ignore_criterion| if ignore_criterion.call(investigator.report) investigator.ignore_report = true break end end end |
#give_name(name, block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/whoops_notifier/strategy.rb', line 39 def give_name(name, block) class << block attr_accessor :name end block.name = name end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/whoops_notifier/strategy.rb', line 46 def inspect "#{name}\nreport modifiers: #{report_modifiers.collect{|r| r.name}.join(", ")}\nignore criteria: #{ignore_criteria.collect{|i| i.name}.join(", ")}" end |