Skip to content

Changing the yielding API#68

Merged
dhh merged 5 commits into
rails:masterfrom
rolftimmermans:yielding-api
Sep 26, 2012
Merged

Changing the yielding API#68
dhh merged 5 commits into
rails:masterfrom
rolftimmermans:yielding-api

Conversation

@rolftimmermans

Copy link
Copy Markdown
Contributor

This PR changes the API of Jbuilder to not require an argument for every block. It also fixes the implementation of cache! to be compatible with this API (see confusion in #63).

Old API:

Jbuilder.encode do |json|
  json.author do |json|
    json.name "Rolf"
  end
  json.attachments @message.attachments do |json, attachment|
    json.filename attachment.filename
  end
end

New API:

Jbuilder.encode do |json|
  json.author do
    json.name "Rolf"
  end
  json.attachments @message.attachments do |attachment|
    json.filename attachment.filename
  end
end

Documentation has been updated, but the old API actually still works. Keeping backwards compatibility was only an issue for the few methods that take a block with 2 arguments. The first argument used to be an instance of a Jbuilder object, the second argument the element for the current iteration. With this change a block with arity 1 only receives the element. The code for that is ugly though. Therefore it would be great if the old API could be deprecated and removed sometime after a major version bump.

@dhh

dhh commented Sep 26, 2012

Copy link
Copy Markdown
Member

Love it!

dhh pushed a commit that referenced this pull request Sep 26, 2012
@dhh dhh merged commit d6e5bb5 into rails:master Sep 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants