Class: ChiliLogger::Values::TypeUniformizer::MainContent
- Inherits:
-
Object
- Object
- ChiliLogger::Values::TypeUniformizer::MainContent
- Defined in:
- lib/helpers/values/type_uniformizer/main_content.rb
Overview
responsible for uniformizing the primitive types of a log’s main_content
Instance Method Summary collapse
-
#error(error) ⇒ Object
a received error must be either a string or Exception descendent(it will be converted to a string).
- #errors(errors) ⇒ Object
-
#initialize ⇒ MainContent
constructor
A new instance of MainContent.
- #main_content(content) ⇒ Object
- #modified_record(record) ⇒ Object
- #modified_records(records) ⇒ Object
Constructor Details
#initialize ⇒ MainContent
Returns a new instance of MainContent.
10 11 12 |
# File 'lib/helpers/values/type_uniformizer/main_content.rb', line 10 def initialize @default = ChiliLogger::Values::Default.new end |
Instance Method Details
#error(error) ⇒ Object
a received error must be either a string or Exception descendent(it will be converted to a string)
54 55 56 57 58 |
# 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) ⇒ Object
47 48 49 50 51 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
43 44 45 |
# File 'lib/helpers/values/type_uniformizer/main_content.rb', line 43 def modified_record(record) record.is_a?(Hash) ? record : {} end |
#modified_records(records) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |