rubygem-jbuilder/Fix-warnings-on-Ruby-2.7.patch
liqiuyu 028eb07ad9 update to 2.9.0
(cherry picked from commit 428dfd0581a67b57756c33cf47f43de8879ed222)
2022-03-04 17:17:00 +08:00

86 lines
2.7 KiB
Diff

From 454d69729ffbde221117992a805f70d3a39b5ba4 Mon Sep 17 00:00:00 2001
From: r7kamura <r7kamura@gmail.com>
Date: Tue, 29 Oct 2019 13:26:47 +0900
Subject: [PATCH] Fix warnings on Ruby 2.7
> warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
This patch converts `Proc.new` calls into `&block`.
---
lib/jbuilder.rb | 16 ++++++++--------
lib/jbuilder/jbuilder_template.rb | 4 ++--
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb
index f062a00..086d5ac 100644
--- a/lib/jbuilder.rb
+++ b/lib/jbuilder.rb
@@ -26,12 +26,12 @@ def self.encode(*args, &block)
BLANK = Blank.new
NON_ENUMERABLES = [ ::Struct, ::OpenStruct ].to_set
- def set!(key, value = BLANK, *args)
+ def set!(key, value = BLANK, *args, &block)
result = if ::Kernel.block_given?
if !_blank?(value)
# json.comments @post.comments { |comment| ... }
# { "comments": [ { ... }, { ... } ] }
- _scope{ array! value, &::Proc.new }
+ _scope{ array! value, &block }
else
# json.comments { ... }
# { "comments": ... }
@@ -61,9 +61,9 @@ def set!(key, value = BLANK, *args)
_set_value key, result
end
- def method_missing(*args)
+ def method_missing(*args, &block)
if ::Kernel.block_given?
- set!(*args, &::Proc.new)
+ set!(*args, &block)
else
set!(*args)
end
@@ -181,11 +181,11 @@ def child!
# json.array! [1, 2, 3]
#
# [1,2,3]
- def array!(collection = [], *attributes)
+ def array!(collection = [], *attributes, &block)
array = if collection.nil?
[]
elsif ::Kernel.block_given?
- _map_collection(collection, &::Proc.new)
+ _map_collection(collection, &block)
elsif attributes.any?
_map_collection(collection) { |element| extract! element, *attributes }
else
@@ -220,9 +220,9 @@ def extract!(object, *attributes)
end
end
- def call(object, *attributes)
+ def call(object, *attributes, &block)
if ::Kernel.block_given?
- array! object, &::Proc.new
+ array! object, &block
else
extract! object, *attributes
end
diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb
index 685922e..4162310 100644
--- a/lib/jbuilder/jbuilder_template.rb
+++ b/lib/jbuilder/jbuilder_template.rb
@@ -73,8 +73,8 @@ def cache_root!(key=nil, options={})
# json.cache_if! !admin?, @person, expires_in: 10.minutes do
# json.extract! @person, :name, :age
# end
- def cache_if!(condition, *args)
- condition ? cache!(*args, &::Proc.new) : yield
+ def cache_if!(condition, *args, &block)
+ condition ? cache!(*args, &block) : yield
end
def target!