Class: SourceMonitor::Sources::TurboStreamPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::RecordIdentifier
Defined in:
lib/source_monitor/sources/turbo_stream_presenter.rb

Overview

Presenter for building Turbo Stream responses for source-related actions Consolidates duplicated response building logic from the controller

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, responder:) ⇒ TurboStreamPresenter

Returns a new instance of TurboStreamPresenter.



12
13
14
15
# File 'lib/source_monitor/sources/turbo_stream_presenter.rb', line 12

def initialize(source:, responder:)
  @source = source
  @responder = responder
end

Instance Attribute Details

#responderObject (readonly)

Returns the value of attribute responder.



10
11
12
# File 'lib/source_monitor/sources/turbo_stream_presenter.rb', line 10

def responder
  @responder
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/source_monitor/sources/turbo_stream_presenter.rb', line 10

def source
  @source
end

Instance Method Details

#render_deletion(metrics:, query:, search_params:, redirect_location: nil) ⇒ Object

Builds the complete Turbo Stream response for source deletion Includes: row removal, heatmap update, empty state (if needed), and redirect (if provided)



19
20
21
22
23
24
25
26
27
28
# File 'lib/source_monitor/sources/turbo_stream_presenter.rb', line 19

def render_deletion(metrics:, query:, search_params:, redirect_location: nil)
  responder.remove_row(source)
  responder.remove("source_monitor_sources_empty_state")

  render_heatmap_update(metrics:, search_params:)
  render_empty_state_if_needed(query:)
  responder.redirect(redirect_location, action: "replace") if redirect_location.present?

  self
end