Module: WinRM::FS::Scripts

Defined in:
lib/winrm-fs/scripts/scripts.rb

Overview

PS1 scripts

Class Method Summary collapse

Class Method Details

.render(template, context) ⇒ Object

rubocop:disable Metrics/MethodLength



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/winrm-fs/scripts/scripts.rb', line 25

def self.render(template, context)
  # rubocop:enable Metrics/MethodLength
  template_path = File.expand_path(
    "#{File.dirname(__FILE__)}/#{template}.ps1.erb"
  )
  template = File.read(template_path)
  case context
  when Hash
    b = binding
    locals = context.collect { |k, _| "#{k} = context[#{k.inspect}]; " }
    b.eval(locals.join)
  when Binding
    b = context
  when NilClass
    b = binding
  else
    raise ArgumentError
  end
  b.eval(Erubi::Engine.new(template).src)
end