Skip to content

Commit 0f4c032

Browse files
committed
Deprecate attr_readers on the renderer instead of just removing them... juuuust in case
1 parent ad10f4e commit 0f4c032

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
module InertiaRails
88
class Renderer
9+
%i[component configuration controller props view_data encrypt_history
10+
clear_history].each do |method_name|
11+
define_method(method_name) do
12+
InertiaRails.deprecator.warn(
13+
"[DEPRECATION] Accessing `InertiaRails::Renderer##{method_name}` is deprecated and will be removed in v4.0"
14+
)
15+
instance_variable_get("@#{method_name}")
16+
end
17+
end
18+
919
def initialize(component, controller, request, response, render_method, **options)
1020
if component.is_a?(Hash) && options.key?(:props)
1121
raise ArgumentError,

spec/inertia/renderer_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe InertiaRails::Renderer do
4+
let(:deprecator) do
5+
double(warn: nil).tap do |deprecator|
6+
allow(InertiaRails).to receive(:deprecator).and_return(deprecator)
7+
end
8+
end
9+
10+
%i[component configuration controller props view_data encrypt_history clear_history].each do |method_name|
11+
it "has a deprecated #{method_name} accessor" do
12+
configuration = double('configuration',
13+
encrypt_history: true,
14+
deep_merge_shared_data: false,
15+
clear_history: false)
16+
17+
controller = double('controller',
18+
inertia_configuration: configuration,
19+
inertia_view_assigns: {},
20+
session: {},
21+
inertia_shared_data: {})
22+
23+
request = double('request', headers: {})
24+
response = double('response', headers: {}, set_header: nil)
25+
render_method = ->(args) {}
26+
27+
renderer = InertiaRails::Renderer.new('MyComponent', controller, request, response, render_method)
28+
29+
expect(deprecator).to receive(:warn)
30+
.with(
31+
"[DEPRECATION] Accessing `InertiaRails::Renderer##{method_name}` is deprecated and will be removed in v4.0"
32+
)
33+
34+
renderer.send(method_name)
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)