Module: Hieracles::Interpolate

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

Instance Method Summary collapse

Instance Method Details

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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]
      puts
      puts "#{match} is not defined."
      puts "Is it missing in your ENC source?"
      puts "Maybe you should define a default value for that scope variable in your config file?"
      puts "Do you want to provide a temmporary value? [input value]"
      print "#{$2} = "
      val = $stdin.gets.chomp
      values[$2.to_sym] = val
      val
    else
      values[$2.to_sym]
    end
  end
end