Class: LiveCable::Rendering::RenderResult

Inherits:
Object
  • Object
show all
Defined in:
lib/live_cable/rendering/render_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(live_id, parts, template_path) ⇒ RenderResult

Returns a new instance of RenderResult.



18
19
20
21
22
23
# File 'lib/live_cable/rendering/render_result.rb', line 18

def initialize(live_id, parts, template_path)
  @live_id = live_id
  @parts = parts
  @template_hash = Digest::SHA256.hexdigest(template_path)[0..11]
  @child_results = {}
end

Instance Attribute Details

#child_resultsHash<String, RenderResult>

Returns:



16
17
18
# File 'lib/live_cable/rendering/render_result.rb', line 16

def child_results
  @child_results
end

#live_idString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/live_cable/rendering/render_result.rb', line 7

def live_id
  @live_id
end

#partsArray<String, nil> (readonly)

Returns:

  • (Array<String, nil>)


10
11
12
# File 'lib/live_cable/rendering/render_result.rb', line 10

def parts
  @parts
end

#template_hashString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/live_cable/rendering/render_result.rb', line 13

def template_hash
  @template_hash
end

Instance Method Details

#as_jsonObject



29
30
31
32
33
34
35
# File 'lib/live_cable/rendering/render_result.rb', line 29

def as_json
  {
    h: template_hash,
    p: parts,
    c: child_results.reject { |_k, v| v.empty? }.as_json,
  }.compact_blank
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/live_cable/rendering/render_result.rb', line 25

def empty?
  parts.compact.empty?
end