class Humidifier::Directory

Represents a directory on the filesystem containing YAML files that correspond to resources belonging to a stack. Contains all of the logic for interfacing with humidifier to deploy stacks, validate them, display them.

Constants

Export

Represents an exported resource in a stack for use in cross-stack references.

Attributes

exports[R]
name[R]
pattern[R]
prefix[R]
stack_name[R]

Public Class Methods

new(name, pattern: nil, prefix: nil) click to toggle source
# File lib/humidifier/directory.rb, line 23
def initialize(name, pattern: nil, prefix: nil)
  @name       = name
  @pattern    = pattern
  @prefix     = prefix
  @exports    = []
  @stack_name = "#{prefix || Humidifier.config.stack_prefix}#{name}"
end

Public Instance Methods

create_change_set() click to toggle source
# File lib/humidifier/directory.rb, line 31
def create_change_set
  return unless valid?

  stack.create_change_set(
    capabilities: %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM]
  )
end
deploy(wait = false, parameter_values = {}) click to toggle source
# File lib/humidifier/directory.rb, line 39
def deploy(wait = false, parameter_values = {})
  return unless valid?

  stack.public_send(
    wait ? :deploy_and_wait : :deploy,
    capabilities: %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM],
    parameters: parameter_values
  )
end
to_cf() click to toggle source
# File lib/humidifier/directory.rb, line 49
def to_cf
  stack.to_cf
end
upload() click to toggle source
# File lib/humidifier/directory.rb, line 53
def upload
  stack.upload if valid?
end
valid?() click to toggle source
# File lib/humidifier/directory.rb, line 57
def valid?
  stack.valid?
end

Private Instance Methods

outputs() click to toggle source
# File lib/humidifier/directory.rb, line 73
def outputs
  exports.each_with_object({}) do |export, exported|
    exported[export.name] =
      Output.new(value: export.value, export_name: export.name)
  end
end
parameters() click to toggle source
# File lib/humidifier/directory.rb, line 80
def parameters
  @parameters ||=
    begin
      parameter_filepath =
        Humidifier.config.files_for(name).detect do |filepath|
          File.basename(filepath, '.yml') == 'parameters'
        end

      parameter_filepath ? parameters_from(parameter_filepath) : {}
    end
end
parameters_from(filepath) click to toggle source
# File lib/humidifier/directory.rb, line 92
def parameters_from(filepath)
  loaded = YAML.load_file(filepath)
  return {} unless loaded

  loaded.each_with_object({}) do |(name, opts), params|
    opts = opts.map { |key, value| [key.to_sym, value] }.to_h
    params[name] = Parameter.new(opts)
  end
end
parse(filepath, type) click to toggle source
# File lib/humidifier/directory.rb, line 102
def parse(filepath, type)
  mapping = Humidifier.config.mapping_for(type)
  return {} if mapping.nil?

  loaded = YAML.load_file(filepath)
  return {} unless loaded

  loaded.each_with_object({}) do |(name, attributes), resources|
    next if pattern && name !~ pattern

    attribute = attributes.delete('export')
    exports << Export.new(name, attribute) if attribute

    resources[name] = mapping.resource_for(name, attributes)
  end
end
resources() click to toggle source
# File lib/humidifier/directory.rb, line 119
def resources
  filepaths = Humidifier.config.files_for(name)

  filepaths.each_with_object({}) do |filepath, resources|
    basename = File.basename(filepath, '.yml')

    # Explicitly skip past parameters so we can pull them out later
    next if basename == 'parameters'

    resources.merge!(parse(filepath, basename))
  end
end
stack() click to toggle source
# File lib/humidifier/directory.rb, line 63
def stack
  Stack.new(
    name: stack_name,
    description: "Resources for #{stack_name}",
    resources: resources,
    outputs: outputs,
    parameters: parameters
  )
end