Sha256: 8ba6e9cd1bb3e5478e15ed455bfa4efd8780191f5e27d080cea43a853d03682b

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

class Lono::Builder::Dsl::Finalizer
  class ParameterGroups
    extend Memoist
    include Lono::Builder::Util::Stringify

    def initialize(cfn, parameters)
      @cfn, @parameters = cfn, parameters
    end

    def run
      return @cfn if parameter_groups.empty?
      @cfn["Metadata"] ||= {}
      @cfn["Metadata"]["AWS::CloudFormation::Interface"] = stringify!(interface)
      @cfn
    end

    def interface
      interface = {}
      parameter_groups.each do |group_label, parameters|
        group = {
          Label: { default: group_label},
          Parameters: parameters,
        }
        interface[:ParameterGroups] ||= []
        interface[:ParameterGroups] << group
      end
      parameter_labels.each do |name, label|
        l = { name => { default: label } }
        interface[:ParameterLabels] ||= {}
        interface[:ParameterLabels].merge!(l)
      end
      interface
    end

    def parameter_groups
      parameter_groups = {}
      @parameters.each do |p|
        next unless p.group_label
        parameter_groups[p.group_label] ||= []
        parameter_groups[p.group_label] << p.name
      end
      parameter_groups
    end
    memoize :parameter_groups

    def parameter_labels
      parameter_labels = {}
      @parameters.each do |p|
        next unless p.label
        parameter_labels[p.name] = p.label
      end
      parameter_labels
    end
    memoize :parameter_labels
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lono-8.0.0.pre.rc2 lib/lono/builder/dsl/finalizer/parameter_groups.rb