Class: Upkeep::Delivery::TurboStreams::Envelope

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stream_nameObject (readonly)

Returns the value of attribute stream_name

Returns:

  • (Object)

    the current value of stream_name



68
69
70
# File 'lib/upkeep/delivery/turbo_streams.rb', line 68

def stream_name
  @stream_name
end

#streamsObject (readonly)

Returns the value of attribute streams

Returns:

  • (Object)

    the current value of streams



68
69
70
# File 'lib/upkeep/delivery/turbo_streams.rb', line 68

def streams
  @streams
end

#subscriber_idObject (readonly)

Returns the value of attribute subscriber_id

Returns:

  • (Object)

    the current value of subscriber_id



68
69
70
# File 'lib/upkeep/delivery/turbo_streams.rb', line 68

def subscriber_id
  @subscriber_id
end

Class Method Details

.shared(stream_name, streams) ⇒ Object



73
74
75
# File 'lib/upkeep/delivery/turbo_streams.rb', line 73

def self.shared(stream_name, streams)
  new("shared:#{stream_name}", streams, stream_name)
end

.subscriber(subscriber_id, streams) ⇒ Object



69
70
71
# File 'lib/upkeep/delivery/turbo_streams.rb', line 69

def self.subscriber(subscriber_id, streams)
  new(subscriber_id, streams, nil)
end

Instance Method Details

#bodyObject



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/upkeep/delivery/turbo_streams.rb', line 77

def body
  seen_refresh_tags = {}
  streams.filter_map do |stream|
    tag = stream.to_html
    next tag unless stream.action == "refresh"
    next if seen_refresh_tags.key?(tag)

    seen_refresh_tags[tag] = true
    tag
  end.join("\n")
end

#reportObject



89
90
91
92
93
94
# File 'lib/upkeep/delivery/turbo_streams.rb', line 89

def report
  {
    subscriber_id: subscriber_id,
    streams: streams.map(&:report)
  }
end