Class: Proteus::Templates::TemplateBinding

Inherits:
Object
  • Object
show all
Includes:
Helpers::PathHelpers, Helpers::StringHelpers
Defined in:
lib/proteus/templates/template_binding.rb

Direct Known Subclasses

Partial

Instance Method Summary collapse

Methods included from Helpers::StringHelpers

#_, #camel_case

Methods included from Helpers::PathHelpers

#config_dir, #config_path, #context_path, #context_temp_directory, #contexts_path, #environments_path, #module_config_path, #module_data_path, #module_hooks_path, #module_io_file, #module_path, #module_templates_path, #modules_path, #plan_file, #root_path, #state_file, #var_file

Constructor Details

#initialize(context:, environment:, module_name:, data: {}, defaults: []) ⇒ TemplateBinding

Returns a new instance of TemplateBinding.



8
9
10
11
12
13
14
15
16
17
# File 'lib/proteus/templates/template_binding.rb', line 8

def initialize(context:, environment:, module_name:, data: {}, defaults:  [])
  @context = context
  @environment = environment
  @module_name = module_name

  data.each do |key, value|
    set(key, value)
  end
  @defaults = defaults
end

Instance Method Details

#default_true(context, key) ⇒ Object



56
57
58
# File 'lib/proteus/templates/template_binding.rb', line 56

def default_true(context, key)
  return context.has_key?(key) ? context[key] : true
end

#get_bindingObject



23
24
25
# File 'lib/proteus/templates/template_binding.rb', line 23

def get_binding
  binding
end

#render_defaults(context, demo: false) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/proteus/templates/template_binding.rb', line 27

def render_defaults(context, demo: false)
  @defaults.inject("") do |memo, default|
    if context.has_key?(default[0])
      memo << "#{demo ? "# " : ""}#{default[0]} = \"#{context[default[0]]}\"\n"
    else
      memo
    end
  end
end

#render_partial(name:, data:, data_context: nil, force_rendering: true, deep_merge: false, scope_resources: nil) ⇒ Object

return output of partial template name: symbol (template_name)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/proteus/templates/template_binding.rb', line 39

def render_partial(name:, data:, data_context: nil, force_rendering: true, deep_merge: false, scope_resources: nil)
  partial = Partial.new(
    name: name.to_s,
    context: @context,
    environment: @environment,
    module_name: @module_name,
    data: data,
    data_context: data_context,
    force_rendering: force_rendering,
    deep_merge: deep_merge,
    terraform_variables: @terraform_variables,
    scope_resources: scope_resources
  )

  partial.render
end

#set(name, value) ⇒ Object



19
20
21
# File 'lib/proteus/templates/template_binding.rb', line 19

def set(name, value)
  instance_variable_set("@#{name}", value)
end