Removing BlankSlate and simplifying implementation #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
This pull request is a follow-up of #54. It is a refactoring of the implementation that achieves a couple of things at the same time, which mostly depend on each other:
Remove dependency on BlankSlate
This removes warnings about
object_id
being unsafe to be undefined (#56). InsteadJbuilder
is now a subclass ofActiveSupport::BasicObject
(for 1.8 compatibility) and loses a dependency.Instance of
Jbuilder
is reused for child elementsThis simplifies the implementation of Jbuilder and reduces the number of objects created. Subclasses also no longer have to implement
_new_instance
, which was error-prone: even the bundledJbuilderTemplate
did it wrong before #54 was merged.This improves performance marginally. Compare before/after (benchmark: https://gist.github.com/3638182 ):
As a side effect, it would be possible to support the following API style:
Of course this would be a breaking API change. So instead of yielding a child
Jbuilder
objectself
is yielded to ensure 100% API-compatibility.Tests are fixed for Ruby 1.8
Ruby 1.8 support was implicit but never actually tested and the tests were written for 1.9. Where necessary, the tests have been adjusted to also run on 1.8.