class SimplyGenius::Atmos::Generator

From github.com/rubber/rubber/blob/master/lib/rubber/commands/vulcanize.rb

Attributes

visited_templates[R]

Public Class Methods

new(**opts) click to toggle source
# File lib/simplygenius/atmos/generator.rb, line 16
def initialize(**opts)
  if opts.has_key?(:dependencies)
    @dependencies = opts.delete(:dependencies)
  else
    @dependencies = true
  end
  @thor_opts = opts
  @thor_generators = {}
  @resolved_templates = {}
  @visited_templates = []
end

Public Instance Methods

apply_template(tmpl) click to toggle source
# File lib/simplygenius/atmos/generator.rb, line 60
def apply_template(tmpl)
  @thor_generators[tmpl.source] ||= Class.new(ThorGenerator) do
    source_root tmpl.source.directory
  end

  gen = @thor_generators[tmpl.source].new(tmpl, self, **@thor_opts)
  gen.apply
  visited_templates << tmpl

  gen # makes testing easier by giving a handle to thor generator instance
end
generate(*template_names, context: {}) click to toggle source
# File lib/simplygenius/atmos/generator.rb, line 28
def generate(*template_names, context: {})
  seen = Set.new

  template_names.each do |template_name|

    # clone since we are mutating context and can be called from within a
    # template, walk_deps also clones
    tmpl = SourcePath.find_template(template_name)
    tmpl.clone.context.merge!(context)

    if @dependencies
      deps = tmpl.walk_dependencies.to_a
    else
      deps = [tmpl]
    end

    deps.each do |dep_tmpl|
      seen_tmpl = [dep_tmpl.name, dep_tmpl.scoped_context]
      unless seen.include?(seen_tmpl)
        apply_template(dep_tmpl)
      end
      seen <<  seen_tmpl
    end

  end

  # TODO: return all context so the calling template can see answers to
  # template questions to use in customizing its output (e.g. service
  # needs cluster name and ec2 backed state)
  return visited_templates
end