Sha256: 7fc84cd2c8a2011a1413b9b8916d4aacf87adc9a5e6b2d1aff6034652ded7ffc

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

module Ufo
  class TemplateScope
    attr_reader :helper
    attr_reader :task_definition_name
    def initialize(helper=nil, task_definition_name=nil)
      @helper = helper
      @task_definition_name = task_definition_name # only available from task_definition
        # not available from params
      load_variables_file("base")
      load_variables_file(Ufo.env)
    end

    # Load the variables defined in ufo/variables/* to make available in the
    # template blocks in ufo/templates/*.
    #
    # Example:
    #
    #   `ufo/variables/base.rb`:
    #     @name = "docker-process-name"
    #     @image = "docker-image-name"
    #
    #   `ufo/templates/main.json.erb`:
    #   {
    #     "containerDefinitions": [
    #       {
    #          "name": "<%= @name %>",
    #          "image": "<%= @image %>",
    #      ....
    #   }
    #
    # NOTE: Only able to make instance variables avaialble with instance_eval
    #   Wasnt able to make local variables available.
    def load_variables_file(filename)
      path = "#{Ufo.root}/.ufo/variables/#{filename}.rb"
      instance_eval(IO.read(path), path) if File.exist?(path)
    end

    def assign_instance_variables
      # copy over the instance variables to make available in RenderMePretty's scope
      hash = {}
      instance_variables.each do |var|
        key = var.to_s.sub('@','') # rid of the leading @
        hash[key.to_sym] = instance_variable_get(var)
      end
      hash
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ufo-3.5.7 lib/ufo/template_scope.rb
ufo-3.5.6 lib/ufo/template_scope.rb
ufo-3.5.5 lib/ufo/template_scope.rb
ufo-3.5.4 lib/ufo/template_scope.rb
ufo-3.5.3 lib/ufo/template_scope.rb
ufo-3.5.2 lib/ufo/template_scope.rb
ufo-3.5.1 lib/ufo/template_scope.rb
ufo-3.5.0 lib/ufo/template_scope.rb