Delegate CollectionDecorator#kind_of? to the underlying decorated collection #497

Merged
merged 2 commits into from Mar 11, 2013

3 participants

@haines
drapergem member

Incorporates #488, using alias_method instead of alias for consistency. Thanks, @jtrim!

Addresses a regression previously addressed in #92. The regression directly affects how nested forms are rendered for has_many associations decorated with 'decorates_associations'.

@jtrim

Thanks for picking this up! However, I think maybe what you intended to do was something along the lines of:

alias_method :orig_kind_of, :kind_of
def kind_of?(klass)
  decorated_collection.kind_of?(klass) || orig_kind_of(klass)
end
alias :is_a? :kind_of?

The line that you replaced in 63721db is necessary as long as we want to maintain the is_a? api likeness to kind_of?. If this is the case, I'm not sure I see the benefit of using alias_method to define an extra instance method as opposed to calling through to super. I could very well be missing something though.

@steveklabnik
drapergem member

The JRuby failures are Travis' fault, so I'm not worrying about that. It's fixed in edge bundler/rubygems, they should be releasing/updating soonish.

I think that this is fine, both of them work, but this way, we don't have the extra method lying around.

@steveklabnik steveklabnik merged commit d5975f2 into drapergem:master Mar 11, 2013

1 check failed

Details default The Travis build failed
@haines haines deleted the haines:collection-decorator-kind-of branch Mar 11, 2013
@haines
drapergem member

@steveklabnik 👍

@jtrim alias and alias_method are pretty much equivalent, and we have tended to use alias_method throughout so I only changed it for consistency's sake... it does exactly the same thing as your version.

@jtrim

Yeah, I tend to prefer plain alias because of the internal Ruby optimizations it provides, but in terms of behavior you're right on equivalency. Sorry about my previous comment - I saw the build failure and jumped to a conclusion about alias_method usage. Thanks for pulling this in!

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