implement actual_template_hash method

This commit is contained in:
Anton Chuchkalov 2015-06-22 12:59:31 +04:00
parent dfb8c82469
commit 0e6de0444e
2 changed files with 37 additions and 3 deletions

View File

@ -17,7 +17,7 @@ module Devops
stack_template_attrs = {
id: stack_template_id,
provider: provider,
template_body: serialize(actual_template_hash(template_preset_hash, template_attrs))
template_body: serialize(actual_template_hash(template_attrs))
}
template_model = Model::StackTemplateFactory.create(provider, stack_template_attrs)
end
@ -36,8 +36,42 @@ module Devops
unserialize(template_preset_body)
end
def actual_template_hash(template_preset_hash, params)
def actual_template_hash(template_attrs)
actual = template_preset_body.dup
template_attrs.each do |key, value|
path = param_attrs_pathes_in_preset[key.to_sym]
next unless path
insert_value_at(actual, value, path)
end
actual
end
# returns hash with keys lists. Better to show an example:
# Imagine tha t template is the following:
# {
# template: {
# users_count: %users_count%
# }
# }
#
# So param_attrs_pathes_in_preset will be
# {users_count: [:template, :users_count]}
def param_attrs_pathes_in_preset
{}
end
# given hash = {t: {a: nil}}, value = 1, path = [:t, :a] returns
# {t: {a: 1}}
def insert_value_at(hash, value, path)
current = hash
path.each_with_index do |key, i|
if i == path.size - 1
current[key] = value
else
current = current[key]
end
end
hash
end
# some templates may be YAML files

View File

@ -20,7 +20,7 @@ module Devops
}
end
def build_stack_template
def self.build_stack_template
lamda {
# check_privileges("stack_template_presets", "r")
check_privileges('stack_template', 'w')