Use log() method instead of puts

This commit is contained in:
Karl Erik Õunapuu 2020-09-04 14:52:24 +03:00
parent dadb8ba88a
commit 5c7e07dbb5
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 23 additions and 8 deletions

View file

@ -12,7 +12,7 @@ module Concerns
def archivable?(post: false)
inactive = inactive?
puts "Found archivable contact id(#{id}), code (#{code})" if inactive && !post
log("Found archivable contact id(#{id}), code (#{code})") if inactive && !post
inactive
end
@ -29,9 +29,9 @@ module Concerns
private
def notify_registrar_about_archivation
registrar.notifications.create!(text: I18n.t('contact_has_been_archived',
contact_code: code,
orphan_months: Setting.orphans_contacts_in_months))
registrar.notifications.create!(
text: I18n.t('contact_has_been_archived',
contact_code: code, orphan_months: Setting.orphans_contacts_in_months))
end
def inactive?
@ -45,6 +45,11 @@ module Concerns
def inactivity_period
Setting.orphans_contacts_in_months.months
end
def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
end
end
end
end

View file

@ -7,9 +7,14 @@ class InactiveContacts
def archive(verified: false)
contacts.each do |contact|
puts "Archiving contact: id(#{contact.id}), code(#{contact.code})"
log("Archiving contact: id(#{contact.id}), code(#{contact.code})")
contact.archive(verified: verified)
yield contact if block_given?
end
end
def log(msg)
@log ||= Logger.new(STDOUT)
@log.info(msg)
end
end