Skip to content

Commit

Permalink
do not persist log entries with empty message
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Tello committed Aug 23, 2017
1 parent c0440d8 commit e05b49a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/logga/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ def log_model_changes
end

def log_field_changes(changes)
if changes.present?
body_generator = ->(record, field, old_value, new_value) { default_change_log_body(record, field, old_value, new_value) }
body = changes.inject([]) do |result, (field, (old_value, new_value))|
result << log_fields.fetch(field.to_sym, body_generator).call(self, field, old_value, new_value)
end.compact.join('\n')
log_receiver&.log_entries&.create(author_data.merge(body: body))
end
return if changes.blank?
body = field_changes_to_message(changes)
log_receiver&.log_entries&.create(author_data.merge(body: body)) if body.present?
end

private
Expand All @@ -61,6 +57,13 @@ def author_data
}
end

def field_changes_to_message(changes)
body_generator = ->(record, field, old_value, new_value) {default_change_log_body(record, field, old_value, new_value)}
changes.inject([]) do |result, (field, (old_value, new_value))|
result << log_fields.fetch(field.to_sym, body_generator).call(self, field, old_value, new_value)
end.compact.join('\n')
end

def default_creation_log_body(record)
[
"#{titleized_model_class_name(record)} created",
Expand Down

0 comments on commit e05b49a

Please sign in to comment.