Class: Lono::Template::Bashify
- Inherits:
-
Object
- Object
- Lono::Template::Bashify
- Defined in:
- lib/lono/template/bashify.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Bashify
constructor
A new instance of Bashify.
- #run ⇒ Object
- #user_data_paths(data, path = "") ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Bashify
Returns a new instance of Bashify.
4 5 6 7 |
# File 'lib/lono/template/bashify.rb', line 4 def initialize(={}) @options = @path = [:path] end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lono/template/bashify.rb', line 22 def run raw = open(@path).read json = JSON.load(raw) paths = user_data_paths(json) if paths.empty? puts "No UserData script found" return end paths.each do |path| puts "UserData script for #{path}:" key = path.sub('/','').split("/").map {|x| "['#{x}']"}.join('') user_data = eval("json#{key}") delimiter = user_data[0] script = user_data[1] puts script.join(delimiter) end end |
#user_data_paths(data, path = "") ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lono/template/bashify.rb', line 9 def user_data_paths(data,path="") paths = [] paths << path data.each do |key,value| if value.is_a?(Hash) paths += user_data_paths(value,"#{path}/#{key}") else paths += ["#{path}/#{key}"] end end paths.select {|p| p =~ /UserData/ && p =~ /Fn::Join/ } end |