Skip to content

Instantly share code, notes, and snippets.

@amiel
Created October 9, 2012 22:45
Show Gist options
  • Save amiel/3861944 to your computer and use it in GitHub Desktop.
Save amiel/3861944 to your computer and use it in GitHub Desktop.
mark as deleted idea
class Image
def mark_as_deleted(build = nil)
# If there's only one undeleted build left, we should only delete the one passed in
# otherwise, we're free to delete them all, and we should delete self as well.
if build && self.has_more_than_one_undeleted_build?
build.mark_as_deleted
else
build.each(&:mark_as_deleted)
self.update_column :deleted_at, Time.current
end
end
end
class Build
# @api: private
def mark_as_deleted
self.update_column :deleted_at, Time.current
end
end
class Image
def mark_as_deleted
not_deleted_builds.each(&:mark_as_deleted)
self.update_column :deleted_at, Time.current
end
end
class Build
# @api: private
def mark_as_deleted
self.update_column :deleted_at, Time.current
image.mark_as_deleted if image.has_no_builds_left?
end
end
class Image
def mark_as_deleted(build = nil)
self.update_column :deleted_at, Time.current
# and do other stuff, but don't call Build#mark_as_deleted
end
end
class Build
def mark_as_deleted
self.update_column :deleted_at, Time.current
# and do other stuff, but don't call Image#mark_as_deleted
end
end
class DeletesImagesAndBuilds # You come up with a better name, it's a service class
def self.delete_image(image)
image.builds.each(&:mark_as_deleted)
image.mark_as_deleted
end
def self.delete_build(build)
build.mark_as_deleted
if build.image.has_no_builds_left?
image.mark_as_deleted
end
end
end
@amiel
Copy link
Author

amiel commented Oct 9, 2012

Just a reminder: I don't know the full scope of the issue, this is one idea

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