Module: Hieracles::Interpolate

Included in:
Node
Defined in:
lib/hieracles/interpolate.rb

Instance Method Summary collapse

Instance Method Details

#ask_about(var) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/hieracles/interpolate.rb', line 15

def ask_about(var)
  @@output.puts
  @@output.puts "'#{var}' is not defined."
  @@output.puts "Is it missing in your ENC source?"
  @@output.puts "Maybe you should define a default value for that scope variable in your config file?"
  @@output.puts "Do you want to provide a temmporary value? [input value]"
  @@output.print "#{var} = "
  @@input.gets.chomp
end

#parse(data, values, interactive = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/hieracles/interpolate.rb', line 4

def parse(data, values, interactive = false)
  data.gsub(/%\{(?:(scope|hiera|literal|alias)\(['"])?(?:::)?([^\}"']*)(?:["']\))?\}/) do |match|
    if interactive && !values[$2.to_sym]
      values[$2.to_sym] = ask_about($2)
      values[$2.to_sym]
    else
      values[$2.to_sym]
    end
  end
end

#setio(input = STDIN, output = STDOUT) ⇒ Object

makes possible to set input and output



26
27
28
29
# File 'lib/hieracles/interpolate.rb', line 26

def setio(input=STDIN, output=STDOUT)
  @@input = input
  @@output = output
end