class ChiliLogger::Values::TypeUniformizer::MainContent
responsible for uniformizing the primitive types of a log's main_content
Public Class Methods
new()
click to toggle source
# File lib/helpers/values/type_uniformizer/main_content.rb, line 10 def initialize @default = ChiliLogger::Values::Default.new end
Public Instance Methods
error(error)
click to toggle source
a received error must be either a string or Exception descendent(it will be converted to a string)
# File lib/helpers/values/type_uniformizer/main_content.rb, line 54 def error(error) error = error.inspect if error.class.ancestors.include?(Exception) # stringifies Exception descendents error = @default.log_error unless error.is_a?(String) error end
errors(errors)
click to toggle source
# File lib/helpers/values/type_uniformizer/main_content.rb, line 47 def errors(errors) return [] unless errors.is_a?(Array) errors.map { |err| error(err) } end
main_content(content)
click to toggle source
# File lib/helpers/values/type_uniformizer/main_content.rb, line 14 def main_content(content) return {} unless content.is_a?(Hash) uniformized_content = {} if content.key?(:modified_records) # only overwrite if :modified_records was explicitly set in main_content mod_recs = content[:modified_records] uniformized_content[:modified_records] = modified_records(mod_recs) end # only overwrite if :errors was explicitly set in main_content uniformized_content[:errors] = errors(content[:errors]) if content.key?(:errors) uniformized_content end
modified_record(record)
click to toggle source
# File lib/helpers/values/type_uniformizer/main_content.rb, line 43 def modified_record(record) record.is_a?(Hash) ? record : {} end
modified_records(records)
click to toggle source
# File lib/helpers/values/type_uniformizer/main_content.rb, line 29 def modified_records(records) return {} unless records.is_a?(Hash) uniformized_recs = {} # modified records should be a hash where each key points to an array of valid modified records records.each do |key, val| val_as_array = val.is_a?(Array) ? val : [].push(val) uniformized_val = val_as_array.map { |record| modified_record(record) } uniformized_recs[key.to_s] = uniformized_val end uniformized_recs end