lib/stimulus_reflex/reflex.rb in stimulus_reflex-3.5.0.pre8 vs lib/stimulus_reflex/reflex.rb in stimulus_reflex-3.5.0.pre9

- old
+ new

@@ -1,10 +1,12 @@ # frozen_string_literal: true -ClientAttributes = Struct.new(:reflex_id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :suppress_logging, keyword_init: true) +ClientAttributes = Struct.new(:reflex_id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :version, :suppress_logging, keyword_init: true) class StimulusReflex::Reflex + class VersionMismatchError < StandardError; end + include ActiveSupport::Rescuable include StimulusReflex::Callbacks include ActionView::Helpers::TagHelper include CableReady::Identifiable @@ -14,11 +16,11 @@ alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name delegate :connection, :stream_name, to: :channel delegate :controller_class, :flash, :session, to: :request delegate :broadcast, :halted, :error, to: :broadcaster - delegate :reflex_id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :suppress_logging, to: :client_attributes + delegate :reflex_id, :tab_id, :reflex_controller, :xpath_controller, :xpath_element, :permanent_attribute_name, :version, :suppress_logging, to: :client_attributes def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, params: {}, client_attributes: {}) if is_a? CableReady::Broadcaster message = <<~MSG @@ -40,9 +42,14 @@ @client_attributes = ClientAttributes.new(client_attributes) @logger = suppress_logging ? nil : StimulusReflex::Logger.new(self) @cable_ready = StimulusReflex::CableReadyChannels.new(stream_name, reflex_id) @payload = {} @headers = {} + + if version != StimulusReflex::VERSION && StimulusReflex.config.on_failed_sanity_checks != :ignore + raise VersionMismatchError.new("stimulus_reflex gem / NPM package version mismatch") + end + self.params end def request @request ||= begin