Class: Itamae::Resource::Template::RenderContext

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/resource/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ RenderContext

Returns a new instance of RenderContext.



19
20
21
22
23
24
25
# File 'lib/itamae/resource/template.rb', line 19

def initialize(resource)
  @resource = resource

  @resource.attributes.variables.each_pair do |key, value|
    instance_variable_set("@#{key}".to_sym, value)
  end
end

Instance Method Details

#nodeObject



35
36
37
# File 'lib/itamae/resource/template.rb', line 35

def node
  @resource.recipe.runner.node
end

#render(template) ⇒ Object



27
28
29
# File 'lib/itamae/resource/template.rb', line 27

def render(template)
  ERB.new(template, nil, '-').result(binding)
end

#render_file(src) ⇒ Object



31
32
33
# File 'lib/itamae/resource/template.rb', line 31

def render_file(src)
  render(::File.read(src))
end