Class: Esse::Jbuilder::ViewTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/jbuilder/view_template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_filename, assigns = {}) ⇒ ViewTemplate

Returns a new instance of ViewTemplate.



27
28
29
30
# File 'lib/esse/jbuilder/view_template.rb', line 27

def initialize(view_filename, assigns = {})
  @view_filename = view_filename
  @assigns = assigns.transform_keys(&:to_sym)
end

Instance Attribute Details

#assignsObject (readonly)

Returns the value of attribute assigns.



21
22
23
# File 'lib/esse/jbuilder/view_template.rb', line 21

def assigns
  @assigns
end

#view_filenameObject (readonly)

Returns the value of attribute view_filename.



21
22
23
# File 'lib/esse/jbuilder/view_template.rb', line 21

def view_filename
  @view_filename
end

Class Method Details

.call(view_filename, assigns = {}) ⇒ Object



23
24
25
# File 'lib/esse/jbuilder/view_template.rb', line 23

def self.call(view_filename, assigns = {})
  new(view_filename, assigns).to_hash
end

Instance Method Details

#to_hashObject



32
33
34
35
36
37
38
# File 'lib/esse/jbuilder/view_template.rb', line 32

def to_hash
  view = Esse::Jbuilder::SearchRequestView.new(assigns)
  hash = JbuilderTemplate.new(view) do |json|
    json._render_template! view_filename
  end.attributes!
  self.class.symbolize_keys ? Esse::HashUtils.deep_transform_keys(hash, &:to_sym) : hash
end