Class: Informed::Informant::Message

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

Overview

Standard message that is logged when informed upon methods are executed.

Direct Known Subclasses

DoneMessage, StartingMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, keyword_arguments:, informee:, also_log:) ⇒ Message

Returns a new instance of Message.



185
186
187
188
189
190
# File 'lib/informed.rb', line 185

def initialize(method:, keyword_arguments:, informee:, also_log:)
  self.keyword_arguments = keyword_arguments
  self.informee = informee
  self.also_log = also_log
  self.method = method
end

Instance Attribute Details

#also_logHash

Returns:



181
182
183
# File 'lib/informed.rb', line 181

def also_log
  @also_log
end

#informeeObject

Returns:



178
179
180
# File 'lib/informed.rb', line 178

def informee
  @informee
end

#keyword_argumentsHash

Returns:



175
176
177
# File 'lib/informed.rb', line 175

def keyword_arguments
  @keyword_arguments
end

#methodSymbol

Returns:



184
185
186
# File 'lib/informed.rb', line 184

def method
  @method
end

Instance Method Details

#to_hHash

The message for the informant to log, in hash form. Actual return value depends on #also_log

Returns:

  • (Hash)


195
196
197
198
199
200
201
202
203
204
205
# File 'lib/informed.rb', line 195

def to_h
  message = { method: method, class: informee.class.name }
  if also_log[:values]
    message[:values] = {}
    also_log[:values].each do |local|
      message[:values][local] ||= keyword_arguments[local] if keyword_arguments.key?(local)
      message[:values][local] ||= informee.send(local) if informee.respond_to?(local, true)
    end
  end
  message
end