Created
October 9, 2012 22:45
-
-
Save amiel/3861944 to your computer and use it in GitHub Desktop.
mark as deleted idea
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
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 |
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
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 |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a reminder: I don't know the full scope of the issue, this is one idea