class Informed::Informant::Message

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

Attributes

also_log[RW]

@return [Hash] from {Informant#also_log}

informee[RW]

@return [Object] from {Informant#inform_on}

keyword_arguments[RW]

@return [Hash] from {Informant#inform_on}

method[RW]

@return [Symbol] from {Informant#method}

Public Class Methods

new(method:, keyword_arguments:, informee:, also_log:) click to toggle source
# 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

Public Instance Methods

to_h() click to toggle source

The message for the informant to log, in hash form. Actual return value depends on {#also_log} @return [Hash]

# 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