Skip to content

Instantly share code, notes, and snippets.

@Sillson
Last active November 12, 2015 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sillson/accdd15de1101b2a50cb to your computer and use it in GitHub Desktop.
Save Sillson/accdd15de1101b2a50cb to your computer and use it in GitHub Desktop.
Output an array of widget names & locations
class OrphanAnnie
class << self
def perform
fake_orphan_locations = mom_is_that_you
write_to_loggers("#{fake_orphan_locations}")
rehome_fake_orphans
write_to_loggers("There are #{Widget.orphans.count} orphans left.")
Resque.enqueue(WidgetCleanupJob)
end
def fake_orphans
Widget.orphans.select {|w| !w.parent_widget.nil?}
end
def mom_is_that_you
web_pages = fake_orphans.map {|w|
loc = Location.find(w.parent_widget.web_template.website.owner_id)
[w.id.to_s+": "+w.name,
w.parent_widget.id.to_s+": "+w.parent_widget.name,
w.parent_widget.parent_widget.id.to_s+": "+w.parent_widget.parent_widget.name,
w.parent_widget.web_template.name]
}
end
def rehome_fake_orphans
fake_orphans.each {|w| self.bind_web_template(w)}
end
def bind_web_template(widget)
widget.update_attribute(:web_template_id, widget.parent_widget.web_template_id)
end
end
end
@Sillson
Copy link
Author

Sillson commented Nov 12, 2015

outputs an array of arrays --

[Widget, Web Page, Location]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment