On Thu, Nov 26, 2009 at 9:24 PM, Emerson Macedo <li...@ruby-forum.com>wrote:

> Fernando Perez wrote:
> > Hi,
> >
> > Let's take the example of the depot app. In my controller I set @order.
> > Then in the view comes the bad stuff:
> >
> > @order.items.each do |item|
> >   item.product.title
> > end
> >
> > Now I'm having problems specing item.product.title. A quick and dirty
> > fix is to trade a for for an underscore, so I create Item#product_title:
> >
> > def product_title
> >   product.title
> > end
> >
> > The problem is that I have a few models that act the same way, so I
> > would find myself writing lot's of these little instance methods, and
> > the solution looks a bit stupid to me. So how do you handle such issue?
> >
> > I thought about composed_of, but AWDWR's examples still break Demeter's
> > law and that annoys me.
> >
> >
> > Thanks in advance
>
> Hi, please try the Law of Demeter gem
>
> Its a DRY way to apply Law of Demeter with demeter gem
>

Interesting. There is a plugin still floating around called Demeter's
Revenge that does a similar thing with associations rather than attributes.
So, in the demeter gem, you can do this:

@post.author_name # same as @post.author.name

Whereas in demeters_revenge you can do this:

@post.create_author # same as @post.author.create

Be nice if both sets of behaviour were in one gem :)
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to