Class: Ufo::TemplateScope

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Settings
Defined in:
lib/ufo/template_scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Settings

#cfn, #network, #settings

Constructor Details

#initialize(helper = nil, task_definition_name = nil) ⇒ TemplateScope

Returns a new instance of TemplateScope.



8
9
10
11
12
13
14
# File 'lib/ufo/template_scope.rb', line 8

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

Instance Attribute Details

#helperObject (readonly)

Returns the value of attribute helper.



6
7
8
# File 'lib/ufo/template_scope.rb', line 6

def helper
  @helper
end

#task_definition_nameObject (readonly)

Returns the value of attribute task_definition_name.



7
8
9
# File 'lib/ufo/template_scope.rb', line 7

def task_definition_name
  @task_definition_name
end

Instance Method Details

#assign_instance_variables(vars) ⇒ Object

Add additional instance variables to template_scope



42
43
44
45
46
# File 'lib/ufo/template_scope.rb', line 42

def assign_instance_variables(vars)
  vars.each do |k,v|
    instance_variable_set("@#{k}".to_sym, v)
  end
end

#load_variables_file(filename) ⇒ Object

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.


36
37
38
39
# File 'lib/ufo/template_scope.rb', line 36

def load_variables_file(filename)
  path = "#{Ufo.root}/.ufo/variables/#{filename}.rb"
  instance_eval(IO.read(path), path) if File.exist?(path)
end

#pretty_name?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
# File 'lib/ufo/template_scope.rb', line 48

def pretty_name?
  # env variable takes highest precedence
  if ENV["STATIC_NAME"]
    ENV["STATIC_NAME"] != "0"
  else
    settings[:pretty_name]
  end
end