Skip to content

Instantly share code, notes, and snippets.

@richmolj
Last active December 18, 2015 18:09
Show Gist options
  • Save richmolj/5824046 to your computer and use it in GitHub Desktop.
Save richmolj/5824046 to your computer and use it in GitHub Desktop.
# DI
class Comment < ActiveRecord::Base
end
class Photo < ActiveRecord::Base
end
class Post
def initialize(comment_repository, photo_repository)
@comment_repository, @post_repository = comment_repository, post_repository
end
def assemble
{
:comments => @comment_repository.all,
:photo => @photo_repository.all
}
end
end
# Non-DI
class Post
def assemble
{
:comments => Comment.all,
:photo => Photo.all
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment