Skip to content

Commit

Permalink
Support metadata Hash comparison to a [value, config] array
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Sep 22, 2023
1 parent d1c5684 commit 6b57eb1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/openhab/core/items/metadata/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module Metadata
#
# All keys are converted to strings.
#
# As a special case, a #== comparison can be done against a [value, config] array.
# @example
# MyItem.metadata[:namespace] = "value", { key: "value" }
# MyItem.metadata[:namespace] == ["value", { "key" => "value" }] #=> true
#
# @!attribute [rw] value
# @return [String] The main value for the metadata namespace.
# @!attribute [r] namespace
Expand Down Expand Up @@ -149,6 +154,8 @@ def ==(other)
return configuration == other.configuration
elsif value.empty? && other.respond_to?(:to_hash)
return configuration == other.to_hash
elsif other.is_a?(Array) && other.length == 2
return value == other.first && configuration == other.last
end
false
end
Expand Down

0 comments on commit 6b57eb1

Please sign in to comment.