Skip to content

Commit b116e14

Browse files
Saup21claude
authored andcommitted
fix: add deep_dup polyfill alongside blank?/present?
active_support's deep_dup is used in 8 places in the gem (matchers, consumer interaction builder). Add a minimal Object/Array/Hash implementation to lib/pact/support/blank.rb so active_support is not required for this either. Prompted by review feedback from @YOU54F. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f5603a3 commit b116e14

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

lib/pact/support/blank.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

3-
# Minimal blank?/present? polyfill for when active_support is not loaded.
4-
# Skipped entirely if Object already responds to blank? (e.g. active_support is present).
3+
# Minimal active_support polyfills for blank?/present? and deep_dup.
4+
# Each block is skipped entirely if the method is already defined
5+
# (e.g. active_support is loaded by the host application).
6+
57
unless Object.method_defined?(:blank?)
68
class NilClass
79
def blank? = true
@@ -38,3 +40,25 @@ def blank? = !self
3840
def present? = !!self
3941
end
4042
end
43+
44+
unless Object.method_defined?(:deep_dup)
45+
class Object
46+
def deep_dup
47+
dup
48+
rescue TypeError
49+
self
50+
end
51+
end
52+
53+
class Array
54+
def deep_dup
55+
map(&:deep_dup)
56+
end
57+
end
58+
59+
class Hash
60+
def deep_dup
61+
each_with_object({}) { |(k, v), h| h[k.deep_dup] = v.deep_dup }
62+
end
63+
end
64+
end

0 commit comments

Comments
 (0)