Class: Upkeep::Delivery::TurboStreams

Inherits:
Object
  • Object
show all
Defined in:
lib/upkeep/delivery/turbo_streams.rb

Defined Under Namespace

Classes: Batch, Envelope, Stream

Instance Method Summary collapse

Instance Method Details

#build(plan) ⇒ Object



121
122
123
# File 'lib/upkeep/delivery/turbo_streams.rb', line 121

def build(plan)
  build_many([plan])
end

#build_many(plans) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/upkeep/delivery/turbo_streams.rb', line 125

def build_many(plans)
  payload = {
    plans: plans.size,
    planned_targets: plans.sum { |plan| plan.targets.size }
  }

  ActiveSupport::Notifications.instrument("build_turbo_streams.upkeep", payload) do
    streams = plans.flat_map { |plan| stream_targets(plan.targets) }
    batch = Batch.new(merge_streams(streams))
    payload.merge!(payload_for(batch, rendered_streams: streams))
    batch
  end
end