From 4dd91e378247e415cb0139e9435f8196262ebc6d Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 12 Sep 2025 20:32:07 +0000 Subject: [PATCH] proxy_stream meta_programming --- app/controllers/application_controller.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 843c82c..ea42dc2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,19 +13,20 @@ class ApplicationController < ActionController::Base end class ProxyStream + # see: https://turbo.hotwired.dev/reference/streams + STREAM_ACTIONS = %i[append prepend replace update remove before after refresh].freeze + STREAM_ACTIONS.each do |method| + define_method(method) do |*streamables, **attributes| + @elements << @turbo_stream.send(method, *streamables, **attributes) + end + end + attr_reader :elements def initialize(turbo_stream) @turbo_stream = turbo_stream @elements = [] end - - def append(*streamables, **attributes) - @elements << @turbo_stream.append(*streamables, **attributes) - end - - def replace(*streamables, **attributes) - @elements << @turbo_stream.replace(*streamables, **attributes) - end end + private_constant(:ProxyStream) end