Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Last active January 29, 2016 07:46
Show Gist options
  • Select an option

  • Save bernardo-cs/b88cac3895d2a1ffe690 to your computer and use it in GitHub Desktop.

Select an option

Save bernardo-cs/b88cac3895d2a1ffe690 to your computer and use it in GitHub Desktop.
simplified collections with duck typing
namespace :assets do
desc "fetch descriptions for youtube videos without descriptions"
task yt_fetch_description: :environment do
BsuDescriptionUpdater.new(YtChanReg, FbPgeReg, IgUsrReg).update_all
end
end
class BsuDescriptionUpdater
def initialize(*source_klasses)
@source_klasses = source_klasses.map { |src| DescriptionUpdater.new(src) }
end
def update_all
binding.pry
@source_klasses.sample.update
#rescue Exception => e
#puts e.message
#puts e.backtrace.inspect
#sleep(10)
#retry
end
class DescriptionUpdater
def initialize(source_klass)
@source_klass = source_klass
end
def update
total = @source_klass.where(description: nil).count
@source_klass.where(description: nil).find_each do |reg|
total -= 1
puts "#{total} #{@source_class.name} descriptions to fetch..."
reg.update_description
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment