app/models/whoops/event.rb in whoops-0.1.9 vs app/models/whoops/event.rb in whoops-0.1.10

- old
+ new

@@ -9,11 +9,11 @@ field :message, :type => String field :event_time, :type => DateTime validates_presence_of :message - before_save :set_keywords + before_save :set_keywords, :sanitize_details def self.record(params) params = params.with_indifferent_access event_group_params = params.slice(*Whoops::EventGroup.field_names) @@ -35,10 +35,43 @@ keywords_array = [] keywords_array << self.message add_details_to_keywords(keywords_array) self.keywords = keywords_array.join(" ") end + + def sanitize_details + if details.is_a? Hash + sanitized_details = {} + details.each do |key, value| + if key =~ /\./ + key = key.gsub(/\./, "_") + end + + if value.is_a? Hash + child_keys = all_keys([value]) + if child_keys.any?{ |child_key| child_key =~ /\./ } + value = value.to_s + end + end + + sanitized_details[key] = value + end + + self.details = sanitized_details + end + end + + def all_keys(values) + keys = [] + values.each do |value| + if value.is_a? Hash + keys |= value.keys + keys |= all_keys(value.values) + end + end + keys + end private def add_details_to_keywords(keywords_array) flattened = details.to_a.flatten @@ -51,8 +84,7 @@ flattened.collect! do |i| i.to_a.flatten - i.keys end.flatten! end - end end \ No newline at end of file