Class: WhoopsLogger::MessageCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/whoops_logger/message_creator.rb

Overview

A “glue” class which coordinates message creation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy, raw_data) ⇒ MessageCreator

Returns a new instance of MessageCreator.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
# File 'lib/whoops_logger/message_creator.rb', line 8

def initialize(strategy, raw_data)
  raise ArgumentError, "strategy can not be nil" if strategy.nil?
  raise ArgumentError, "strategy must respond to 'call'" unless strategy.respond_to?(:call)
  self.strategy = strategy
  self.raw_data = raw_data
  self.message = Message.new
  self.message.event_time = Time.now
  self.message.logger_strategy_name = strategy.respond_to?(:name) ? strategy.name : 'anonymous'
end

Instance Attribute Details

#messageObject

get data from raw_data using a strategy to create a message and decide whether it should be ignored



6
7
8
# File 'lib/whoops_logger/message_creator.rb', line 6

def message
  @message
end

#raw_dataObject

get data from raw_data using a strategy to create a message and decide whether it should be ignored



6
7
8
# File 'lib/whoops_logger/message_creator.rb', line 6

def raw_data
  @raw_data
end

#strategyObject

get data from raw_data using a strategy to create a message and decide whether it should be ignored



6
7
8
# File 'lib/whoops_logger/message_creator.rb', line 6

def strategy
  @strategy
end

Instance Method Details

#create!Object



18
19
20
# File 'lib/whoops_logger/message_creator.rb', line 18

def create!
  strategy.call(message, raw_data)
end

#ignore_message?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/whoops_logger/message_creator.rb', line 22

def ignore_message?
  message.ignore?
end