Sha256: 0da30f11453c8ab7c645c66d9e040b785cd495f6499e8ffc8396a671d8a4ae41

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require 'open-uri'

class Lono::Builder::Template
  class Bashify
    include Lono::Utils::Logging

    def initialize(options={})
      @options = options
      @path = options[:path]
    end

    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

    def run
      raw = open(@path).read
      json = JSON.load(raw)
      paths = user_data_paths(json)
      if paths.empty?
        logger.info "No UserData script found"
        return
      end
      paths.each do |path|
        logger.info "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]
        logger.info script.join(delimiter)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lono-8.0.0.pre.rc6 lib/lono/builder/template/bashify.rb
lono-8.0.0.pre.rc5 lib/lono/builder/template/bashify.rb
lono-8.0.0.pre.rc4 lib/lono/builder/template/bashify.rb
lono-8.0.0.pre.rc3 lib/lono/builder/template/bashify.rb
lono-8.0.0.pre.rc2 lib/lono/builder/template/bashify.rb
lono-8.0.0.pre.rc1 lib/lono/builder/template/bashify.rb