DEV: Drop OpenStruct for the context object in services

While using `OpenStruct` is nice, it’s generally not a very good idea as
it usually leads to performance problems.

The `OpenStruct` source code even says basically to avoid it.

Since the context object is crucial in our services, this patch replaces
`OpenStruct` with a custom implementation instead.
This commit is contained in:
Loïc Guitaut
2024-10-03 18:05:45 +02:00
committed by Loïc Guitaut
parent 974a3bfc41
commit 229773e7a8
20 changed files with 145 additions and 143 deletions

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
RSpec.describe StepsInspector do
RSpec.describe Service::StepsInspector do
class DummyService
include Service::Base
@@ -239,7 +239,7 @@ RSpec.describe StepsInspector do
end
context "when a reason is provided" do
before { result["result.policy.policy"].reason = "failed" }
before { result["result.policy.policy"][:reason] = "failed" }
it "returns the reason" do
expect(error).to eq "failed"

View File

@@ -26,7 +26,7 @@ module ServiceMatchers
private
def error_message_with_inspection(message)
inspector = StepsInspector.new(result)
inspector = Service::StepsInspector.new(result)
"#{message}\n\n#{inspector.inspect}\n\n#{inspector.error}"
end
end
@@ -89,7 +89,7 @@ module ServiceMatchers
end
def error_message_with_inspection(message)
inspector = StepsInspector.new(result)
inspector = Service::StepsInspector.new(result)
"#{message}\n\n#{inspector.inspect}\n\n#{inspector.error}"
end
@@ -158,7 +158,7 @@ module ServiceMatchers
end
def inspect_steps(result)
inspector = StepsInspector.new(result)
inspector = Service::StepsInspector.new(result)
puts "Steps:"
puts inspector.inspect
puts "\nFirst error:"