Class: WhoopsLogger::Strategy
- Inherits:
-
Object
- Object
- WhoopsLogger::Strategy
- Defined in:
- lib/whoops_logger/strategy.rb
Overview
Strategies are responsible for building messages and determining whether a a message should be ignored.
Each strategy contains any number of message builders and ignore criteria.
Each message builder and ignore criteria takes a name. This makes adding a message builder or ignore criteria more like adding a method - the name makes it easier to see the intention of the code. It also makes it easier to get useful info when you inspect the strategy.
Strategies use call to actually apply modifiers and criteria for the same reason that Rack uses call. Conceivably, you could add a strategy to the notifier with WhoopsLogger.strategies = lambda{ |message, raw_data|
.details = raw_data[:detail]
} or something along those lines.
Instance Attribute Summary collapse
-
#ignore_criteria ⇒ Object
Returns the value of attribute ignore_criteria.
-
#message_builders ⇒ Object
Returns the value of attribute message_builders.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#add_ignore_criteria(name, &block) ⇒ Object
block takes one param, the message_creator’s message.
-
#add_message_builder(name, &block) ⇒ Object
block should take two params, the message and the raw_data use raw_data to build the message.
- #call(message, raw_data) ⇒ 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.
23 24 25 26 27 28 |
# File 'lib/whoops_logger/strategy.rb', line 23 def initialize(name) self.name = name self.ignore_criteria = [] self. = [] WhoopsLogger.strategies[name] = self end |
Instance Attribute Details
#ignore_criteria ⇒ Object
Returns the value of attribute ignore_criteria.
21 22 23 |
# File 'lib/whoops_logger/strategy.rb', line 21 def ignore_criteria @ignore_criteria end |
#message_builders ⇒ Object
Returns the value of attribute message_builders.
21 22 23 |
# File 'lib/whoops_logger/strategy.rb', line 21 def @message_builders end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/whoops_logger/strategy.rb', line 21 def name @name end |
Instance Method Details
#add_ignore_criteria(name, &block) ⇒ Object
block takes one param, the message_creator’s message
51 52 53 54 |
# File 'lib/whoops_logger/strategy.rb', line 51 def add_ignore_criteria(name, &block) give_name(name, block) @ignore_criteria << block end |
#add_message_builder(name, &block) ⇒ Object
block should take two params, the message and the raw_data use raw_data to build the message
45 46 47 48 |
# File 'lib/whoops_logger/strategy.rb', line 45 def (name, &block) give_name(name, block) @message_builders << block end |
#call(message, raw_data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/whoops_logger/strategy.rb', line 30 def call(, raw_data) .each do || .call(, raw_data) end ignore_criteria.each do |ignore_criterion| if ignore_criterion.call(, raw_data) .ignore = true break end end end |
#give_name(name, block) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/whoops_logger/strategy.rb', line 56 def give_name(name, block) class << block attr_accessor :name end block.name = name end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/whoops_logger/strategy.rb', line 63 def inspect "#{name}\nmessage builders: #{.collect{|r| r.name}.join(", ")}\nignore criteria: #{ignore_criteria.collect{|i| i.name}.join(", ")}" end |