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


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

def node
  @resource.recipe.runner.node
end

#render_file(src) ⇒ Object


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

def render_file(src)
  template = ::File.read(src)
  ERB.new(template, nil, '-').tap do |erb|
    erb.filename = src
  end.result(binding)
end