Class: Ufo::TemplateScope
- Inherits:
-
Object
- Object
- Ufo::TemplateScope
- Defined in:
- lib/ufo/template_scope.rb
Instance Attribute Summary collapse
-
#helper ⇒ Object
readonly
Returns the value of attribute helper.
-
#task_definition_name ⇒ Object
readonly
Returns the value of attribute task_definition_name.
Instance Method Summary collapse
- #assign_instance_variables ⇒ Object
-
#initialize(helper = nil, task_definition_name = nil) ⇒ TemplateScope
constructor
A new instance of TemplateScope.
-
#load_variables_file(filename) ⇒ Object
Load the variables defined in ufo/variables/* to make available in the template blocks in ufo/templates/*.
Constructor Details
#initialize(helper = nil, task_definition_name = nil) ⇒ TemplateScope
Returns a new instance of TemplateScope.
5 6 7 8 9 10 11 |
# File 'lib/ufo/template_scope.rb', line 5 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
#helper ⇒ Object (readonly)
Returns the value of attribute helper.
3 4 5 |
# File 'lib/ufo/template_scope.rb', line 3 def helper @helper end |
#task_definition_name ⇒ Object (readonly)
Returns the value of attribute task_definition_name.
4 5 6 |
# File 'lib/ufo/template_scope.rb', line 4 def task_definition_name @task_definition_name end |
Instance Method Details
#assign_instance_variables ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ufo/template_scope.rb', line 38 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 |
#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.
33 34 35 36 |
# File 'lib/ufo/template_scope.rb', line 33 def load_variables_file(filename) path = "#{Ufo.root}/.ufo/variables/#{filename}.rb" instance_eval(IO.read(path), path) if File.exist?(path) end |