lib/lono/param/generator.rb in lono-6.1.11 vs lib/lono/param/generator.rb in lono-7.0.0

- old
+ new

@@ -1,46 +1,40 @@ class Lono::Param - class Generator - include Lono::Blueprint::Root - include Lono::Conventions - + class Generator < Lono::AbstractBase attr_reader :env_path, :base_path # set when generate is called - def initialize(blueprint, options={}) - # dup because we're modifying the Thor frozen hash - # HashWithIndifferentAccess.new again because .dup changes it to a normal Hash - @blueprint, @options = blueprint, ActiveSupport::HashWithIndifferentAccess.new(options.dup) - @options[:stack] ||= @blueprint - set_blueprint_root(@blueprint) - @template, @param = template_param_convention(options) - end def generate puts "Generating parameter files for blueprint #{@blueprint.color(:green)}:" @base_path, @env_path = config_locations - return unless @base_path || @env_path + return {} unless @base_path || @env_path # useful option for lono cfn, since some templates dont require params - return if @options[:allow_not_exists] && !params_exist? + return {} if @options[:allow_not_exists] && !params_exist? if params_exist? contents = process_erb data = convert_to_cfn_format(contents) - json = JSON.pretty_generate(data) + camel_data = convert_to_cfn_format(contents, :camel) + json = JSON.pretty_generate(camel_data) write_output(json) unless @options[:mute] short_output_path = output_path.sub("#{Lono.root}/","") puts " #{short_output_path}" end else puts "#{@base_path} or #{@env_path} could not be found? Are you sure it exist?" exit 1 end - json + data end + def parameters + generate + end + def config_locations @base_path = lookup_config_location("base") @env_path = lookup_config_location(Lono.env) if ENV['LONO_DEBUG_PARAM'] @@ -51,14 +45,11 @@ [@base_path, @env_path] end def lookup_config_location(env) - options = @options.clone - options[:blueprint] = @blueprint - options[:stack] ||= @blueprint - location = Lono::ConfigLocation.new("params", options, env) + location = Lono::ConfigLocation.new("params", @options, env) env == "base" ? location.lookup_base : location.lookup end def puts_param_message(type) path = send("#{type}_path") @@ -76,21 +67,10 @@ def params_exist? @base_path && File.exist?(@base_path) || @env_path && File.exist?(@env_path) end - # useful for when calling CloudFormation via the aws-sdk gem - def params(casing = :underscore) - @base_path, @env_path = config_locations - - # useful option for lono cfn - return {} if @options[:allow_not_exists] && !params_exist? - - contents = process_erb - convert_to_cfn_format(contents, casing) - end - # Reads both the base source and env source and overlay the two # Example 1: # params/base/mystack.txt - base path # params/production/mystack.txt - env path # @@ -124,11 +104,11 @@ end # Context for ERB rendering. # This is where we control what references get passed to the ERB rendering. def context - @context ||= Lono::Template::Context.new(@blueprint, @options) + @context ||= Lono::Template::Context.new(@options) end def parse_contents(contents) lines = contents.split("\n") # remove comment at the end of the line @@ -138,10 +118,10 @@ # filter out empty lines lines = lines.reject { |l| l.strip.empty? } lines end - def convert_to_cfn_format(contents, casing=:camel) + def convert_to_cfn_format(contents, casing=:underscore) lines = parse_contents(contents) # First use a Hash structure so that overlay env files will override # the base param file. data = {} \ No newline at end of file