Last active
January 29, 2016 07:46
-
-
Save bernardo-cs/b88cac3895d2a1ffe690 to your computer and use it in GitHub Desktop.
simplified collections with duck typing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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