Skip to content

Commit

Permalink
Bring back Registers#values_at
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
isimluk committed Dec 25, 2022
1 parent c2c6cb2 commit 6a34fd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/liquid/registers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/unit/registers_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a34fd1

Please sign in to comment.