Skip to content

Instantly share code, notes, and snippets.

@g5codyswartz
Forked from Sillson/name_me_a_widget.rb
Last active December 31, 2015 08:30
Show Gist options
  • Save g5codyswartz/0f05cf42428d69c7a66a to your computer and use it in GitHub Desktop.
Save g5codyswartz/0f05cf42428d69c7a66a to your computer and use it in GitHub Desktop.
Output an array of widget names & locations
class OrphanAnnie
def self.perform
lost_souls = mom_is_that_you
write_to_loggers("#{lost_souls}")
end
def self.mom_is_that_you
names = Widget.orphans.select {|i| !i.parent_widget.nil?}
web_pages = names.map {|w|
self.get_infos(w)
}
end
def self.get_infos(widget)
loc = Location.find(widget.parent_widget.web_template.website.owner_id)
[widget.id.to_s+": "+widget.name,
widget.parent_widget.id.to_s+": "+widget.parent_widget.name+" | Web Template ID: "+widget.parent_widget.web_template_id.to_s,
widget.parent_widget.parent_widget.id.to_s+": "+widget.parent_widget.parent_widget.name+" | Web Template ID: "+widget.parent_widget.parent_widget.web_template_id.to_s,
widget.parent_widget.web_template.name,
loc.name+" | Internal Name: "+loc.internal_branded_name]
end
def self.self_adoption(lost_id)
orphan = Widget.find(lost_id)
self.adopt_parent(lost_id, orphan.parent_widget_id)
end
def self.adopt_parent(lost_id, parent_id)
orphan = Widget.find(lost_id)
parent = Widget.find(parent_id)
self.update_web_template_id(orphan, parent.web_template_id)
end
def self.update_web_template_id(orphan, web_template_id)
orphan.update_attributes({web_template_id: web_template_id})
end
def self.auto_self_adopt
Widget.orphans.select {|i| !i.parent_widget.nil?}.each { |w| self.self_adoption(w.id) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment