Skip to content

Commit ae0b115

Browse files
committed
fix: remove ostruct dependency for Ruby 3.5+ compatibility
Replace OpenStruct with custom PropertyStruct implementation to ensure compatibility with Ruby 3.5+ where ostruct is being removed from the standard library. The PropertyStruct class provides the same dynamic attribute access functionality as OpenStruct but without requiring the external gem. Fixes rkoster/rubionic-workspace#229 Related to cloudfoundry#708
1 parent 06110bc commit ae0b115

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

templatescompiler/erbrenderer/erb_renderer.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
# Based on common/properties/template_evaluation_context.rb
22
require "rubygems"
3-
require "ostruct"
43
require "json"
54
require "erb"
65
require "yaml"
76

7+
# Simple struct-like class to replace OpenStruct dependency
8+
# OpenStruct is being removed from Ruby standard library in Ruby 3.5+
9+
class PropertyStruct
10+
def initialize(hash = {})
11+
@table = {}
12+
hash.each do |key, value|
13+
@table[key.to_sym] = value
14+
end
15+
end
16+
17+
def method_missing(method_name, *args)
18+
if method_name.to_s.end_with?("=")
19+
@table[method_name.to_s.chomp("=").to_sym] = args.first
20+
else
21+
@table[method_name.to_sym]
22+
end
23+
end
24+
25+
def respond_to_missing?(method_name, include_private = false)
26+
true
27+
end
28+
end
29+
830
class Hash
931
def recursive_merge!(other)
1032
self.merge!(other) do |_, old_value, new_value|
@@ -99,7 +121,7 @@ def openstruct(object)
99121
case object
100122
when Hash
101123
mapped = object.inject({}) { |h, (k,v)| h[k] = openstruct(v); h }
102-
OpenStruct.new(mapped)
124+
PropertyStruct.new(mapped)
103125
when Array
104126
object.map { |item| openstruct(item) }
105127
else

0 commit comments

Comments
 (0)