Class: Interfacets::Shared::View::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/interfacets/shared/view.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity:, channels:, block:) ⇒ Evaluator

Returns a new instance of Evaluator.



12
13
14
15
16
17
# File 'lib/interfacets/shared/view.rb', line 12

def initialize(entity:, channels:, block:)
  @entity = entity
  @channels = channels
  @block = block
  @data = Hash.new { |h, k| h[k] = { streams: {} } }
end

Instance Attribute Details

#block ⇒ Object (readonly)

Returns the value of attribute block.



11
12
13
# File 'lib/interfacets/shared/view.rb', line 11

def block
  @block
end

#channels ⇒ Object (readonly)

Returns the value of attribute channels.



11
12
13
# File 'lib/interfacets/shared/view.rb', line 11

def channels
  @channels
end

#entity ⇒ Object (readonly)

Returns the value of attribute entity.



11
12
13
# File 'lib/interfacets/shared/view.rb', line 11

def entity
  @entity
end

Class Method Details

.call(**p) ⇒ Object



7
8
9
# File 'lib/interfacets/shared/view.rb', line 7

def self.call(**p)
  new(**p).call
end

Instance Method Details

#call ⇒ Object



19
20
21
# File 'lib/interfacets/shared/view.rb', line 19

def call
  instance_exec(entity, &@block)
end

#channel(name) ⇒ Object



43
44
45
# File 'lib/interfacets/shared/view.rb', line 43

def channel(name)
  @channels.fetch(name)
end

#render(entity) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/interfacets/shared/view.rb', line 23

def render(entity)
  entity
    .class
    .view
    .render(
      entity:,
      channels:
    )
end

#render_to(channel_id, stream: "default", &block) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/interfacets/shared/view.rb', line 33

def render_to(channel_id, stream: "default", &block)
  channel_id = channel_id.to_s

  channels
    .fetch(channel_id)
    .builder(stream.to_s)
    .then { @current_builder = _1 }
    .then { instance_exec(_1, &block) }
end