module Dunlop::WorkflowStepModel::NotesHandling
  extend ActiveSupport::Concern

  def notes=(append_text)
    change_time = attribute_change_time || Time.current
    write_attribute :notes,
      "#{notes}\n\n#{change_time.iso8601} #{User.current.try(:email)}\n#{append_text}".strip
  end

  def append_note(value)
    write_attribute :notes, [notes, value].join("\n")
  end

  def replace_notes(value)
    write_attribute :notes, value
  end
  alias_method :replace_notes=, :replace_notes

  def replace_notes!(value)
    replace_notes value
    save
  end

end

