Sha256: 2c103d07bb5eed0fa072b35b840eba2e3523c3dba51c03cfb0a7fc585b5fcb44

Contents?: true

Size: 930 Bytes

Versions: 6

Compression:

Stored size: 930 Bytes

Contents

module Hieracles
  module Interpolate

    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

    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

    # makes possible to set input and output
    def setio(input=STDIN, output=STDOUT)
      @@input = input
      @@output = output
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hieracles-0.3.2 lib/hieracles/interpolate.rb
hieracles-0.3.1 lib/hieracles/interpolate.rb
hieracles-0.3.0 lib/hieracles/interpolate.rb
hieracles-0.2.2 lib/hieracles/interpolate.rb
hieracles-0.2.1 lib/hieracles/interpolate.rb
hieracles-0.2.0 lib/hieracles/interpolate.rb