Class: StackMaster::TemplateCompilers::SparkleFormation

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_master/template_compilers/sparkle_formation.rb

Constant Summary collapse

CompileTime =
StackMaster::SparkleFormation::CompileTime

Class Method Summary collapse

Class Method Details

.compile(template_dir, template, compile_time_parameters, compiler_options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 14

def self.compile(template_dir, template, compile_time_parameters, compiler_options = {})
  sparkle_template = compile_sparkle_template(template_dir, template, compiler_options)
  definitions = sparkle_template.parameters
  validate_definitions(definitions)
  validate_parameters(definitions, compile_time_parameters)

  sparkle_template.compile_time_parameter_setter do
    sparkle_template.compile_state = create_state(definitions, compile_time_parameters)
  end

  JSON.pretty_generate(sparkle_template.dump)
end

.compile_sparkle_template(template_dir, template, compiler_options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 29

def self.compile_sparkle_template(template_dir, template, compiler_options)
  sparkle_path =
    if compiler_options['sparkle_path']
      File.expand_path(compiler_options['sparkle_path'])
    else
      template_dir
    end

  collection = ::SparkleFormation::SparkleCollection.new
  root_pack = ::SparkleFormation::Sparkle.new(
    :root => sparkle_path,
  )
  collection.set_root(root_pack)
  if compiler_options['sparkle_packs']
    compiler_options['sparkle_packs'].each do |pack_name|
      require pack_name
      pack = ::SparkleFormation::SparklePack.new(:name => pack_name)
      collection.add_sparkle(pack)
    end
  end

  if compiler_options['sparkle_pack_template']
    unless collection.templates['aws'].include? template
      raise ArgumentError.new("Template #{template.inspect} not found in any sparkle pack")
    end

    template_file_path = collection.templates['aws'][template].top['path']
  else
    template_file_path = File.join(template_dir, template)
  end

  sparkle_template = compile_template_with_sparkle_path(template_file_path, sparkle_path)
  sparkle_template.sparkle.apply(collection)
  sparkle_template
end

.compile_template_with_sparkle_path(template_path, sparkle_path) ⇒ Object



65
66
67
68
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 65

def self.compile_template_with_sparkle_path(template_path, sparkle_path)
  ::SparkleFormation.sparkle_path = sparkle_path
  ::SparkleFormation.compile(template_path, :sparkle)
end

.create_state(definitions, compile_time_parameters) ⇒ Object



78
79
80
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 78

def self.create_state(definitions, compile_time_parameters)
  CompileTime::StateBuilder.new(definitions, compile_time_parameters).build
end

.require_dependenciesObject



9
10
11
12
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 9

def self.require_dependencies
  require 'sparkle_formation'
  require 'stack_master/sparkle_formation/template_file'
end

.validate_definitions(definitions) ⇒ Object



70
71
72
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 70

def self.validate_definitions(definitions)
  CompileTime::DefinitionsValidator.new(definitions).validate
end

.validate_parameters(definitions, compile_time_parameters) ⇒ Object



74
75
76
# File 'lib/stack_master/template_compilers/sparkle_formation.rb', line 74

def self.validate_parameters(definitions, compile_time_parameters)
  CompileTime::ParametersValidator.new(definitions, compile_time_parameters).validate
end