class Tataru::InitHashCompiler

compiles the inithash

Public Class Methods

new(dsl) click to toggle source
# File lib/tataru/init_hash_compiler.rb, line 6
def initialize(dsl)
  @dsl = dsl
end

Public Instance Methods

generate_init_hash() click to toggle source
# File lib/tataru/init_hash_compiler.rb, line 16
def generate_init_hash
  rom = {}
  @dsl.resources.each do |k, v|
    # Expand all the values used to a big flat hash that
    # is only one level deep for ease of use, then mark
    # them for the vm to use
    flattener = Flattener.new(v)
    flattener.flattened.each do |key, value|
      fixed = value.dup
      if fixed[:references]
        fixed[:references] = resolved_references(k, fixed[:references])
      end
      rom[key.to_s.sub(/^top/, k)] = fixed
    end
  end
  {
    rom: rom,
    remote_ids: {}
  }
end
resolved_references(resource_name, references) click to toggle source
# File lib/tataru/init_hash_compiler.rb, line 10
def resolved_references(resource_name, references)
  references.map do |field, refname|
    [field, refname.to_s.sub(/^top/, resource_name)]
  end.to_h
end
result() click to toggle source
# File lib/tataru/init_hash_compiler.rb, line 37
def result
  @result ||= generate_init_hash
end