Skip to content

Instantly share code, notes, and snippets.

@indrekj
Created June 23, 2012 15:28
Show Gist options
  • Save indrekj/2978684 to your computer and use it in GitHub Desktop.
Save indrekj/2978684 to your computer and use it in GitHub Desktop.
class Post
class Mapper
include SomeMapper
def self.find(id)
post = super
if post.published_at
PublishedPost.new(post)
else
Draft.new(post)
end
end
def self.save(derived_post)
post = derived_post.__getobj__
super(post)
end
end
end
class PublishedPost < SimpleDelegator
end
class Draft < SimpleDelegator
def publish
self.published_at = Time.now
PublishedPost.new(__getobj__)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment