Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ERB Renderer Ruby Tests

on: [push, pull_request]

jobs:
test_property_struct:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- run: bundle install
working-directory: templatescompiler/erbrenderer/
- run: bundle exec rake
working-directory: templatescompiler/erbrenderer/
continue-on-error: ${{ matrix.ruby == 'head' }}
3 changes: 3 additions & 0 deletions templatescompiler/erbrenderer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.bundle/
vendor/bundle/
Gemfile.lock
6 changes: 6 additions & 0 deletions templatescompiler/erbrenderer/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

group :test do
gem "rake"
gem "rspec"
end
5 changes: 5 additions & 0 deletions templatescompiler/erbrenderer/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task default: [:spec]
26 changes: 24 additions & 2 deletions templatescompiler/erbrenderer/erb_renderer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
# Based on common/properties/template_evaluation_context.rb
require "rubygems"
require "ostruct"
require "json"
require "erb"
require "yaml"

# Simple struct-like class to replace OpenStruct dependency
# OpenStruct is being removed from Ruby standard library in Ruby 3.5+
class PropertyStruct
def initialize(hash = {})
@table = {}
hash.each do |key, value|
@table[key.to_sym] = value
end
end

def method_missing(method_name, *args)
if method_name.to_s.end_with?("=")
@table[method_name.to_s.chomp("=").to_sym] = args.first
else
@table[method_name.to_sym]
end
end

def respond_to_missing?(method_name, include_private = false)
true
end
end

class Hash
def recursive_merge!(other)
self.merge!(other) do |_, old_value, new_value|
Expand Down Expand Up @@ -99,7 +121,7 @@ def openstruct(object)
case object
when Hash
mapped = object.inject({}) { |h, (k,v)| h[k] = openstruct(v); h }
OpenStruct.new(mapped)
PropertyStruct.new(mapped)
when Array
object.map { |item| openstruct(item) }
else
Expand Down
Loading
Loading