Class: RSpecPuppetUtils::TemplateHarness

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_puppet_utils/template_harness.rb

Defined Under Namespace

Classes: Isolator

Instance Method Summary collapse

Constructor Details

#initialize(template, scope = nil) ⇒ TemplateHarness

Returns a new instance of TemplateHarness.



7
8
9
10
# File 'lib/rspec_puppet_utils/template_harness.rb', line 7

def initialize(template, scope = nil)
  @template = template
  @isolator = Isolator.new(scope)
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
# File 'lib/rspec_puppet_utils/template_harness.rb', line 17

def run
  b = @isolator.get_binding
  inline = !File.exists?(@template)
  template_string = inline ? @template : File.new(@template).read
  template = ERB.new(template_string, 0, '-')
  template.filename = File.expand_path(@template) unless inline
  template.result b
end

#set(name, value) ⇒ Object



12
13
14
15
# File 'lib/rspec_puppet_utils/template_harness.rb', line 12

def set(name, value)
  var_name = name.start_with?('@') ? name : "@#{name}"
  @isolator.instance_variable_set(var_name, value)
end