Class: Tataru::InitHashCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/tataru/init_hash_compiler.rb

Overview

compiles the inithash

Instance Method Summary collapse

Constructor Details

#initialize(dsl) ⇒ InitHashCompiler

Returns a new instance of InitHashCompiler.



6
7
8
# File 'lib/tataru/init_hash_compiler.rb', line 6

def initialize(dsl)
  @dsl = dsl
end

Instance Method Details

#generate_init_hashObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



10
11
12
13
14
# 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

#resultObject



37
38
39
# File 'lib/tataru/init_hash_compiler.rb', line 37

def result
  @result ||= generate_init_hash
end