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



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def action
  @action
end

#deoptimization_reasonObject (readonly)

Returns the value of attribute deoptimization_reason

Returns:

  • (Object)

    the current value of deoptimization_reason



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def deoptimization_reason
  @deoptimization_reason
end

#htmlObject (readonly)

Returns the value of attribute html

Returns:

  • (Object)

    the current value of html



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def html
  @html
end

#html_digestObject (readonly)

Returns the value of attribute html_digest

Returns:

  • (Object)

    the current value of html_digest



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def html_digest
  @html_digest
end

#identity_signatureObject (readonly)

Returns the value of attribute identity_signature

Returns:

  • (Object)

    the current value of identity_signature



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

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



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

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



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

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



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

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



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def subscriber_ids
  @subscriber_ids
end

#targetObject (readonly)

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def target
  @target
end

#target_selectorObject (readonly)

Returns the value of attribute target_selector

Returns:

  • (Object)

    the current value of target_selector



9
10
11
# File 'lib/upkeep/delivery/turbo_streams.rb', line 9

def target_selector
  @target_selector
end

Instance Method Details

#for_subscriber?(subscriber_id) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/upkeep/delivery/turbo_streams.rb', line 33

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

#rendered?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/upkeep/delivery/turbo_streams.rb', line 29

def rendered?
  action != "remove"
end

#reportObject



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

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



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

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