From 86b394640a186f65f2ee194428e750d7d483d263 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Thu, 8 May 2025 15:29:43 -0400 Subject: [PATCH 01/19] Optimize options merging --- lib/jbuilder/jbuilder_template.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 55f2d5f..c929c6a 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -4,11 +4,7 @@ require 'active_support/cache' class JbuilderTemplate < Jbuilder - class << self - attr_accessor :template_lookup_options - end - - self.template_lookup_options = { handlers: [:jbuilder] } + HANDLERS = [:jbuilder].freeze def initialize(context, *args) @context = context @@ -137,14 +133,14 @@ def set!(name, object = BLANK, *args) private def _render_partial_with_options(options) - options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached) - options.reverse_merge! ::JbuilderTemplate.template_lookup_options + options[:locals] ||= options.except(:partial, :as, :collection, :cached) + options[:handlers] ||= ::JbuilderTemplate::HANDLERS as = options[:as] if as && options.key?(:collection) && CollectionRenderer.supported? collection = options.delete(:collection) || [] partial = options.delete(:partial) - options[:locals].merge!(json: self) + options[:locals][:json] = self collection = EnumerableCompat.new(collection) if collection.respond_to?(:count) && !collection.respond_to?(:size) if options.has_key?(:layout) @@ -173,8 +169,8 @@ def _render_partial_with_options(options) locals = options.delete(:locals) array! collection do |member| member_locals = locals.clone - member_locals.merge! collection: collection - member_locals.merge! as => member + member_locals[:collection] = collection + member_locals[as] = member _render_partial options.merge(locals: member_locals) end else @@ -186,7 +182,7 @@ def _render_partial_with_options(options) end def _render_partial(options) - options[:locals].merge! json: self + options[:locals][:json] = self @context.render options end From 866d2892c2b9fe4c407cb4437f954afd9637d8c3 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Fri, 9 May 2025 12:31:03 -0400 Subject: [PATCH 02/19] Call _set_value directly --- lib/jbuilder/jbuilder_template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index c929c6a..5228d5a 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -244,7 +244,7 @@ def _set_inline_partial(name, object, options) _scope{ _render_partial_with_options options.merge(locals: locals) } end - set! name, value + _set_value name, value end def _render_explicit_partial(name_or_options, locals = {}) From c6b9bffed86c5a8dbdab0e475c92377b7eec1387 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Mon, 12 May 2025 11:48:07 -0400 Subject: [PATCH 03/19] Put template_lookup_options to avoid possible breaking change --- lib/jbuilder/jbuilder_template.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 5228d5a..b4ba87e 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -4,7 +4,11 @@ require 'active_support/cache' class JbuilderTemplate < Jbuilder - HANDLERS = [:jbuilder].freeze + class << self + attr_accessor :template_lookup_options + end + + self.template_lookup_options = { handlers: [:jbuilder] } def initialize(context, *args) @context = context @@ -134,7 +138,7 @@ def set!(name, object = BLANK, *args) def _render_partial_with_options(options) options[:locals] ||= options.except(:partial, :as, :collection, :cached) - options[:handlers] ||= ::JbuilderTemplate::HANDLERS + options[:handlers] ||= ::JbuilderTemplate.template_lookup_options[:handlers] as = options[:as] if as && options.key?(:collection) && CollectionRenderer.supported? From ba3a6274a9827773769f24a39956358059be7d11 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Mon, 12 May 2025 12:13:21 -0400 Subject: [PATCH 04/19] Save on more merges --- lib/jbuilder/jbuilder_template.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index b4ba87e..3dac041 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -118,7 +118,8 @@ def array!(collection = [], *args) options = args.first if args.one? && _partial_options?(options) - partial! options.merge(collection: collection) + options[:collection] = collection + partial! options else super end @@ -175,7 +176,8 @@ def _render_partial_with_options(options) member_locals = locals.clone member_locals[:collection] = collection member_locals[as] = member - _render_partial options.merge(locals: member_locals) + options[:locals] = member_locals + _render_partial options end else array! @@ -242,10 +244,16 @@ def _set_inline_partial(name, object, options) value = if object.nil? [] elsif _is_collection?(object) - _scope{ _render_partial_with_options options.merge(collection: object) } + _scope do + options[:collection] = object + _render_partial_with_options options + end else locals = ::Hash[options[:as], object] - _scope{ _render_partial_with_options options.merge(locals: locals) } + _scope do + options[:locals] = locals + _render_partial_with_options options + end end _set_value name, value @@ -259,7 +267,8 @@ def _render_explicit_partial(name_or_options, locals = {}) else # partial! 'name', locals: {foo: 'bar'} if locals.one? && (locals.keys.first == :locals) - options = locals.merge(partial: name_or_options) + locals[:partial] = name_or_options + options = locals else options = { partial: name_or_options, locals: locals } end From 9ca4d0526996d1dfc6e97f1f9ccbc8d971581038 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Mon, 12 May 2025 16:50:23 -0400 Subject: [PATCH 05/19] Save memory allocation when calling render --- lib/jbuilder/jbuilder_template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 3dac041..74ed66e 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -189,7 +189,7 @@ def _render_partial_with_options(options) def _render_partial(options) options[:locals][:json] = self - @context.render options + @context.render options, nil end def _cache_fragment_for(key, options, &block) From 8f9993a3daadd60919a36c3df885fccd97992ce2 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Mon, 21 Jul 2025 14:59:54 -0400 Subject: [PATCH 06/19] Stop mutating options in array! method --- lib/jbuilder/jbuilder_template.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index e165ef6..44219f3 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -121,8 +121,9 @@ def array!(collection = [], *args) options = args.first if args.one? && _partial_options?(options) + options = options.dup options[:collection] = collection - partial! options + _render_partial_with_options options else super end From d23ebe2c3f9d5231262c58d911461bce19812a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 21 Jul 2025 19:09:37 +0000 Subject: [PATCH 07/19] Add devcontainer --- .devcontainer/devcontainer.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..96f29c1 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ruby +{ + "name": "jbuilder", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "ghcr.io/rails/devcontainer/images/ruby:3.4.5", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {} + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "ruby --version", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} From 7ea07fd12c324e41fec19709514e8b3112191506 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:10:39 +0100 Subject: [PATCH 08/19] Fix warning about routes.rb not existing The controller scaffold generator tries to insert routes but there isn't a routes file the tmp folder so it prints a warning instead. Prevent the warning from being printed by using the option to skip routes. --- test/scaffold_api_controller_generator_test.rb | 6 +++--- test/scaffold_controller_generator_test.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/scaffold_api_controller_generator_test.rb b/test/scaffold_api_controller_generator_test.rb index 8ab4708..546749b 100644 --- a/test/scaffold_api_controller_generator_test.rb +++ b/test/scaffold_api_controller_generator_test.rb @@ -4,7 +4,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator - arguments %w(Post title body:text images:attachments --api) + arguments %w(Post title body:text images:attachments --api --skip-routes) destination File.expand_path('../tmp', __FILE__) setup :prepare_destination @@ -53,7 +53,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase end test "don't use require and permit if there are no attributes" do - run_generator %w(Post --api) + run_generator %w(Post --api --skip-routes) assert_file 'app/controllers/posts_controller.rb' do |content| assert_match %r{def post_params}, content @@ -62,7 +62,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase end test 'handles virtual attributes' do - run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"] + run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes) assert_file 'app/controllers/messages_controller.rb' do |content| if Rails::VERSION::MAJOR >= 8 diff --git a/test/scaffold_controller_generator_test.rb b/test/scaffold_controller_generator_test.rb index 795dec8..048df2a 100644 --- a/test/scaffold_controller_generator_test.rb +++ b/test/scaffold_controller_generator_test.rb @@ -4,7 +4,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator - arguments %w(Post title body:text images:attachments) + arguments %w(Post title body:text images:attachments --skip-routes) destination File.expand_path('../tmp', __FILE__) setup :prepare_destination @@ -67,7 +67,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end test 'controller with namespace' do - run_generator %w(Admin::Post --model-name=Post) + run_generator %w(Admin::Post --model-name=Post --skip-routes) assert_file 'app/controllers/admin/posts_controller.rb' do |content| assert_instance_method :create, content do |m| assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m @@ -84,7 +84,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end test "don't use require and permit if there are no attributes" do - run_generator %w(Post) + run_generator %w(Post --skip-routes) assert_file 'app/controllers/posts_controller.rb' do |content| assert_match %r{def post_params}, content @@ -93,7 +93,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end test 'handles virtual attributes' do - run_generator %w(Message content:rich_text video:attachment photos:attachments) + run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes) assert_file 'app/controllers/messages_controller.rb' do |content| if Rails::VERSION::MAJOR >= 8 From b58d524c59cb6d9aa81efb11d8e4c2c41ba40f9e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:13:43 +0100 Subject: [PATCH 09/19] Use the correct path for the env command --- bin/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/test b/bin/test index 45d4fe9..1bc5120 100755 --- a/bin/test +++ b/bin/test @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash set -e bundle install From 1a86eb8d94967fcc04cf90282f7e071b87028ef2 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:28:07 +0100 Subject: [PATCH 10/19] Add Rails 7.2 to the Appraisals file --- .github/workflows/ruby.yml | 5 +++++ Appraisals | 4 ++++ gemfiles/rails_7_2.gemfile | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 gemfiles/rails_7_2.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 0d5374d..3bc499a 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -24,14 +24,19 @@ jobs: gemfile: - "rails_7_0" - "rails_7_1" + - "rails_7_2" - "rails_8_0" - "rails_head" exclude: + - ruby: '3.0' + gemfile: rails_7_2 - ruby: '3.0' gemfile: rails_8_0 - ruby: '3.0' gemfile: rails_head + - ruby: '3.1' + gemfile: rails_7_2 - ruby: '3.1' gemfile: rails_8_0 - ruby: '3.1' diff --git a/Appraisals b/Appraisals index 3d1832d..3caeb7e 100644 --- a/Appraisals +++ b/Appraisals @@ -9,6 +9,10 @@ appraise "rails-7-1" do gem "rails", "~> 7.1.0" end +appraise "rails-7-2" do + gem "rails", "~> 7.2.0" +end + appraise "rails-8-0" do gem "rails", "~> 8.0.0" end diff --git a/gemfiles/rails_7_2.gemfile b/gemfiles/rails_7_2.gemfile new file mode 100644 index 0000000..8f5a412 --- /dev/null +++ b/gemfiles/rails_7_2.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", "~> 7.2.0" + +gemspec path: "../" From 13e033b7de6cfaeb643995436c9dc39ea63b715a Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:32:36 +0100 Subject: [PATCH 11/19] Fix method redefinition warning --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index d985da9..0b4dfa6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,7 +19,7 @@ ENV["RAILS_ENV"] ||= "test" class << Rails - def cache + redefine_method :cache do @cache ||= ActiveSupport::Cache::MemoryStore.new end end From f447b6035abf83decc3afd98ae123b704af6951e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 18 Sep 2024 11:33:38 +0100 Subject: [PATCH 12/19] Fix constant redefinition warning In e18fe2a the Jbuilder::VERSION constant was introduced but in 9aa3dd9 it was used in the gemspec which changed the loading order so that the version constant was loaded first. This defined Jbuilder as an Object subclass rather than the intended BasicObject and when jbuilder/jbuilder was required it redefined the Jbuilder constant and obliterates the VERSION constant. This commit ensures that the version constant exists and the Jbuilder parent class is BasicObject. --- lib/jbuilder.rb | 1 - lib/jbuilder/errors.rb | 2 +- lib/jbuilder/jbuilder.rb | 2 +- lib/jbuilder/version.rb | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 024e418..edf048c 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -5,7 +5,6 @@ require 'jbuilder/blank' require 'jbuilder/key_formatter' require 'jbuilder/errors' -require 'jbuilder/version' require 'json' require 'active_support/core_ext/hash/deep_merge' diff --git a/lib/jbuilder/errors.rb b/lib/jbuilder/errors.rb index e2de671..aba1f89 100644 --- a/lib/jbuilder/errors.rb +++ b/lib/jbuilder/errors.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'jbuilder/jbuilder' +require 'jbuilder/version' class Jbuilder class NullError < ::NoMethodError diff --git a/lib/jbuilder/jbuilder.rb b/lib/jbuilder/jbuilder.rb index 1fc3025..ddb5273 100644 --- a/lib/jbuilder/jbuilder.rb +++ b/lib/jbuilder/jbuilder.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -Jbuilder = Class.new(BasicObject) +require 'jbuilder/version' diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb index 3fe2e27..8d4d5e2 100644 --- a/lib/jbuilder/version.rb +++ b/lib/jbuilder/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class Jbuilder +class Jbuilder < BasicObject VERSION = "2.13.0" end From 8474b41f666b13055b9368107c783cdae7903fb6 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Mon, 21 Jul 2025 15:31:57 -0400 Subject: [PATCH 13/19] Remove _partial micro-optimization --- lib/jbuilder/jbuilder_template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 44219f3..1d1afdc 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -178,7 +178,7 @@ def _render_partial_with_options(options) def _render_partial(options) options[:locals][:json] = self - @context.render options, nil + @context.render options end def _cache_fragment_for(key, options, &block) From 7e16adf446c9da701e1e5fdbe9c93f7f8095630d Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Wed, 23 Jul 2025 14:05:41 -0400 Subject: [PATCH 14/19] Stop mutating options in set! method --- lib/jbuilder/jbuilder_template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 1d1afdc..5b64e5a 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -133,7 +133,7 @@ def set!(name, object = BLANK, *args) options = args.first if args.one? && _partial_options?(options) - _set_inline_partial name, object, options + _set_inline_partial name, object, options.dup else super end From b7b5abb02d9bb2ed1fc584a08142838a05cafc08 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Wed, 23 Jul 2025 14:05:51 -0400 Subject: [PATCH 15/19] Stop mutating options in partial! method --- lib/jbuilder/jbuilder_template.rb | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 5b64e5a..a44cc2c 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -55,7 +55,9 @@ def partial!(*args) if args.one? && _is_active_model?(args.first) _render_active_model_partial args.first else - _render_explicit_partial(*args) + options = args.extract_options!.dup + options[:partial] = args.first if args.present? + _render_partial_with_options options end end @@ -248,28 +250,6 @@ def _set_inline_partial(name, object, options) _set_value name, value end - def _render_explicit_partial(name_or_options, locals = {}) - case name_or_options - when ::Hash - # partial! partial: 'name', foo: 'bar' - options = name_or_options - else - # partial! 'name', locals: {foo: 'bar'} - if locals.one? && (locals.keys.first == :locals) - locals[:partial] = name_or_options - options = locals - else - options = { partial: name_or_options, locals: locals } - end - # partial! 'name', foo: 'bar' - as = locals.delete(:as) - options[:as] = as if as.present? - options[:collection] = locals[:collection] if locals.key?(:collection) - end - - _render_partial_with_options options - end - def _render_active_model_partial(object) @context.render object, json: self end From 6fd6c0662f6507be951ba842857c663adb000f56 Mon Sep 17 00:00:00 2001 From: Michael Oberegger Date: Wed, 23 Jul 2025 14:07:19 -0400 Subject: [PATCH 16/19] Small _set_inline_partial optimization --- lib/jbuilder/jbuilder_template.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index a44cc2c..855dd67 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -240,9 +240,8 @@ def _set_inline_partial(name, object, options) _render_partial_with_options options end else - locals = ::Hash[options[:as], object] _scope do - options[:locals] = locals + options[:locals] = { options[:as] => object } _render_partial_with_options options end end From 30ba7df152aacdf20b6267a82b9d2b1f9e947636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 8 Aug 2025 19:46:18 +0000 Subject: [PATCH 17/19] Prepare for 2.14.0 --- lib/jbuilder/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb index 8d4d5e2..79d5e2b 100644 --- a/lib/jbuilder/version.rb +++ b/lib/jbuilder/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Jbuilder < BasicObject - VERSION = "2.13.0" + VERSION = "2.14.0" end From a6863b5d582b966fcfbef8686c829c950efd1f5c Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 12 Aug 2025 09:58:22 -0400 Subject: [PATCH 18/19] Ensure that Jbuilder.encode properly forwards arguments to .new The initializer previously accepted an options hash, but now takes kwargs. So the encode method also needs to accept (and forward) kwargs. --- lib/jbuilder.rb | 4 ++-- test/jbuilder_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index edf048c..1290839 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -28,8 +28,8 @@ def initialize( end # Yields a builder and automatically turns the result into a JSON string - def self.encode(*args, &block) - new(*args, &block).target! + def self.encode(...) + new(...).target! end BLANK = Blank.new diff --git a/test/jbuilder_test.rb b/test/jbuilder_test.rb index eec22f1..c01fb1e 100644 --- a/test/jbuilder_test.rb +++ b/test/jbuilder_test.rb @@ -936,4 +936,11 @@ class JbuilderTest < ActiveSupport::TestCase result = JSON.load(Jbuilder.encode { |json| json.time Time.parse("2018-05-13 11:51:00.485 -0400") }) assert_equal "2018-05-13T11:51:00.485-04:00", result["time"] end + + test "encode forwards options to new" do + Jbuilder.encode(key_formatter: 1, ignore_nil: 2) do |json| + assert_equal 1, json.instance_eval{ @key_formatter } + assert_equal 2, json.instance_eval{ @ignore_nil } + end + end end From 38339adaa9d44ba89c0dde2a795338a886941e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 12 Aug 2025 15:37:46 +0000 Subject: [PATCH 19/19] Prepare for 2.14.1 --- lib/jbuilder/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb index 79d5e2b..78151fd 100644 --- a/lib/jbuilder/version.rb +++ b/lib/jbuilder/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Jbuilder < BasicObject - VERSION = "2.14.0" + VERSION = "2.14.1" end