Class: Chatwerk::Views::BaseView

Inherits:
Object
  • Object
show all
Defined in:
lib/chatwerk/views/base_view.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**data) ⇒ BaseView

Returns a new instance of BaseView.



12
13
14
15
# File 'lib/chatwerk/views/base_view.rb', line 12

def initialize(**data)
  @data = data
  @output = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object (private)



36
37
38
# File 'lib/chatwerk/views/base_view.rb', line 36

def method_missing(name, *args, **kwargs, &block)
  @data[name]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/chatwerk/views/base_view.rb', line 10

def data
  @data
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/chatwerk/views/base_view.rb', line 10

def output
  @output
end

Class Method Details

.render(**data) ⇒ Object



6
7
8
# File 'lib/chatwerk/views/base_view.rb', line 6

def self.render(**data)
  new(**data).render
end

Instance Method Details

#renderObject



17
18
19
20
21
22
23
# File 'lib/chatwerk/views/base_view.rb', line 17

def render
  @output = nil
  temp = template(**data)
  return temp if @output.nil? # allow templates to return a string instead

  @output
end