Module: Hieracles::Interpolate
- Included in:
- Node
- Defined in:
- lib/hieracles/interpolate.rb
Instance Method Summary collapse
- #ask_about(var) ⇒ Object
- #extract(data) ⇒ Object
- #parse(data, values, interactive = false) ⇒ Object
- #regex ⇒ Object
-
#setio(input = STDIN, output = STDOUT) ⇒ Object
makes possible to set input and output.
Instance Method Details
#ask_about(var) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/hieracles/interpolate.rb', line 22 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 |
#extract(data) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/hieracles/interpolate.rb', line 15 def extract(data) data.scan(regex).reduce([]) do |a, m| a << m[1] unless a.include?(m[1]) a end 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(regex) 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 |
#regex ⇒ Object
38 39 40 |
# File 'lib/hieracles/interpolate.rb', line 38 def regex /%\{(?:(scope|hiera|literal|alias)\(['"])?(?:::)?([^\}"']*)(?:["']\))?\}/ end |
#setio(input = STDIN, output = STDOUT) ⇒ Object
makes possible to set input and output
33 34 35 36 |
# File 'lib/hieracles/interpolate.rb', line 33 def setio(input=STDIN, output=STDOUT) @@input = input @@output = output end |