jbuilder

https://github.com/rails/jbuilder

Ruby

Jbuilder: generate JSON objects with a Builder-style DSL

JbuilderTemplate#cache_root!

Caches the json structure at the root using a string rather than the hash structure. This is considerably
faster, but the drawback is that it only works, as the name hints, at the root. So you cannot
use this approach to cache deeper inside the hierarchy, like in partials or such. Continue to use #cache! there.

Example:

  json.cache_root! @person do
    json.extract! @person, :name, :age
  end

  # json.extra 'This will not work either, the root must be exclusive'

Source | Google | Stack overflow

Edit

git clone git@github.com:rails/jbuilder.git

cd jbuilder

open lib/jbuilder/jbuilder_template.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-JbuilderTemplate-cache_root--for-pr


# Commit to git

git add lib/jbuilder/jbuilder_template.rbgit commit -m "better docs for JbuilderTemplate#cache_root!"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-JbuilderTemplate-cache_root--for-pr

hub pull-request


# Celebrate!