Skip to content

Instantly share code, notes, and snippets.

@michalkorzawski
Last active September 5, 2022 19:54
Show Gist options
  • Save michalkorzawski/352f98ec0d0248082ddd6cb60a080bcd to your computer and use it in GitHub Desktop.
Save michalkorzawski/352f98ec0d0248082ddd6cb60a080bcd to your computer and use it in GitHub Desktop.
# app/services/importers/users.rb
module Importers
class Users
include CableReady::Broadcaster
def initialize(file:)
@file = file
end
def import_csv
counter = 0
total = CSV.read(@file.path, headers: true).length
CSV.foreach(@file.path, headers: true) do |csv_row|
counter += 1
...
cable_ready[UserChannel].text_content(
selector: '#processed-row-number-container',
text: counter
).broadcast_to(Current.user)
# more about Current.user -> https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment