module Humidifier::Loader

Reads the specs/CloudFormationResourceSpecification.json file and load each resource as a class

Public Class Methods

load() click to toggle source

loop through the specs and register each class

# File lib/humidifier/loader.rb, line 32
def load
  parsed = parse_spec
  types = PropertyTypes.new(parsed['PropertyTypes'])

  parsed['ResourceTypes'].each do |key, spec|
    match = key.match(/\A(\w+)::(\w+)::(\w+)\z/)
    register(match[1], match[2], match[3], spec, types.search(key))
  end

  Humidifier.registry.freeze
end

Private Class Methods

build_class(aws_name, spec, substructs) click to toggle source
# File lib/humidifier/loader.rb, line 46
def build_class(aws_name, spec, substructs)
  Class.new(Resource) do
    self.aws_name = aws_name
    self.props =
      spec['Properties'].map do |(key, config)|
        prop = Props.from(key, config, substructs)
        [prop.name, prop]
      end.to_h
  end
end
parse_spec() click to toggle source
# File lib/humidifier/loader.rb, line 57
def parse_spec
  relative =
    File.join('..', '..', 'CloudFormationResourceSpecification.json')

  JSON.parse(File.read(File.expand_path(relative, __dir__)))
end
register(top, group, resource, spec, substructs) click to toggle source
# File lib/humidifier/loader.rb, line 64
def register(top, group, resource, spec, substructs)
  aws_name = "#{top}::#{group}::#{resource}"
  resource_class = build_class(aws_name, spec, substructs)

  unless Humidifier.const_defined?(group)
    Humidifier.const_set(group, Module.new)
  end

  Humidifier.const_get(group).const_set(resource, resource_class)
  Humidifier.registry[aws_name] = resource_class
end