Class: Upkeep::Delivery::TurboStreams::Stream

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def action
  @action
end

#deoptimization_reasonObject (readonly)

Returns the value of attribute deoptimization_reason

Returns:

  • (Object)

    the current value of deoptimization_reason



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def deoptimization_reason
  @deoptimization_reason
end

#htmlObject (readonly)

Returns the value of attribute html

Returns:

  • (Object)

    the current value of html



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def html
  @html
end

#html_digestObject (readonly)

Returns the value of attribute html_digest

Returns:

  • (Object)

    the current value of html_digest



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def html_digest
  @html_digest
end

#identity_signatureObject (readonly)

Returns the value of attribute identity_signature

Returns:

  • (Object)

    the current value of identity_signature



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def identity_signature
  @identity_signature
end

#matched_dependency_keysObject (readonly)

Returns the value of attribute matched_dependency_keys

Returns:

  • (Object)

    the current value of matched_dependency_keys



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def matched_dependency_keys
  @matched_dependency_keys
end

#render_duration_msObject (readonly)

Returns the value of attribute render_duration_ms

Returns:

  • (Object)

    the current value of render_duration_ms



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def render_duration_ms
  @render_duration_ms
end

#shared_stream_nameObject (readonly)

Returns the value of attribute shared_stream_name

Returns:

  • (Object)

    the current value of shared_stream_name



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def shared_stream_name
  @shared_stream_name
end

#subscriber_idsObject (readonly)

Returns the value of attribute subscriber_ids

Returns:

  • (Object)

    the current value of subscriber_ids



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def subscriber_ids
  @subscriber_ids
end

#targetObject (readonly)

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def target
  @target
end

#target_selectorObject (readonly)

Returns the value of attribute target_selector

Returns:

  • (Object)

    the current value of target_selector



11
12
13
# File 'lib/upkeep/delivery/turbo_streams.rb', line 11

def target_selector
  @target_selector
end

Instance Method Details

#for_subscriber?(subscriber_id) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/upkeep/delivery/turbo_streams.rb', line 35

def for_subscriber?(subscriber_id)
  subscriber_ids.include?(subscriber_id)
end

#rendered?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/upkeep/delivery/turbo_streams.rb', line 31

def rendered?
  action != "remove"
end

#reportObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/upkeep/delivery/turbo_streams.rb', line 39

def report
  {
    action: action,
    target: target.to_h,
    target_selector: target_selector,
    identity_signature: identity_signature,
    shared_stream_name: shared_stream_name,
    html_digest: html_digest,
    subscriber_ids: subscriber_ids,
    matched_dependency_keys: matched_dependency_keys,
    deoptimization_reason: deoptimization_reason,
    render_duration_ms: render_duration_ms
  }
end

#to_htmlObject



24
25
26
27
28
29
# File 'lib/upkeep/delivery/turbo_streams.rb', line 24

def to_html
  attributes = %(action="#{CGI.escapeHTML(action)}" targets="#{CGI.escapeHTML(target_selector)}")
  return %(<turbo-stream #{attributes}></turbo-stream>) if action == "remove"

  %(<turbo-stream #{attributes}><template>#{html}</template></turbo-stream>)
end