From 6a34fd177f1741eea22391f73f0c9bdc4af5f222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Sun, 25 Dec 2022 21:37:46 +0000 Subject: [PATCH] Bring back Registers#values_at Previously, registers returned from liquid have been plain hashes and thus users of the library were able to call `#value_at` on the registers. This ability has been removed by the introduction of Liquid::Registers class. --- lib/liquid/registers.rb | 4 ++++ test/unit/registers_unit_test.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/liquid/registers.rb b/lib/liquid/registers.rb index 0b65d862c..af7425cd7 100644 --- a/lib/liquid/registers.rb +++ b/lib/liquid/registers.rb @@ -44,6 +44,10 @@ def fetch(key, default = UNDEFINED, &block) def key?(key) @changes.key?(key) || @static.key?(key) end + + def values_at(*keys) + keys.collect { |key| fetch(key) } + end end # Alias for backwards compatibility diff --git a/test/unit/registers_unit_test.rb b/test/unit/registers_unit_test.rb index caa718eab..1147dda25 100644 --- a/test/unit/registers_unit_test.rb +++ b/test/unit/registers_unit_test.rb @@ -60,6 +60,13 @@ def test_fetch assert_equal("default 2", result) end + def test_values_at + static_register = Registers.new(a: 1, b: 2) + assert_equal([1, 2], static_register.values_at(:a, :b)) + assert_equal([2, 1], static_register.values_at(:b, :a)) + assert_equal([2], static_register.values_at(:b)) + end + def test_key static_register = Registers.new(a: 1, b: 2) static_register[:b] = 22