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)


42
43
44
# File 'lib/upkeep/delivery/turbo_streams.rb', line 42

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

#morph_action?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/upkeep/delivery/turbo_streams.rb', line 38

def morph_action?
  %w[replace update].include?(action)
end

#rendered?Boolean

Returns:

  • (Boolean)


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

def rendered?
  !%w[remove refresh].include?(action)
end

#reportObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/upkeep/delivery/turbo_streams.rb', line 46

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
30
31
32
# File 'lib/upkeep/delivery/turbo_streams.rb', line 24

def to_html
  return %(<turbo-stream action="refresh" method="morph" scroll="preserve"></turbo-stream>) if action == "refresh"

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

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