module Kontena::Cli::Stacks::Common::StackValuesFromOption::InstanceMethods

Public Instance Methods

dependency_values_from_options(name) click to toggle source

Transforms a hash dependency_values_from_options('foo.bar' => 1, 'foo')

=> { 'bar' => 1 }

Used for dependency variable injection

# File lib/kontena/cli/stacks/common.rb, line 159
def dependency_values_from_options(name)
  name_with_dot = name.to_s + '.'
  values_from_options.each_with_object({}) do |kv_pair, obj|
    key = kv_pair.first.to_s
    value = kv_pair.last
    next unless key.start_with?(name_with_dot)
    obj[key.sub(name_with_dot, '')] = value
  end
end
read_values_from_stacks(stackname) click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 118
def read_values_from_stacks(stackname)
  result = {}
  response = client.get("stacks/#{current_grid}/#{stackname}")
  result.merge!(response['variables']) if response['variables']
  if response['children']
    response['children'].each do |child_info|
      result.merge!(
        read_values_from_stacks(child_info['name']).tap do |child_result|
          child_result.keys.each do |key|
            new_key = child_info['name'].dup # foofoo-redis-monitor
            new_key.sub!("#{stackname}-", '') # monitor
            new_key.concat ".#{key}" # monitor.foovariable
            child_result[new_key] = child_result.delete(key)
          end
        end
      )
    end
  end
  result
end
values_from_file() click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 139
def values_from_file
  @values_from_file ||= {}
end
values_from_installed_stacks() click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 147
def values_from_installed_stacks
  @values_from_installed_stacks ||= {}
end
values_from_options() click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 151
def values_from_options
  @values_from_options ||= values_from_installed_stacks.merge(values_from_file).merge(values_from_value_options)
end
values_from_value_options() click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 143
def values_from_value_options
  @values_from_value_options ||= {}
end