class Sanctum::GetConfig::ConfigMerge

Attributes

config_file[R]
force[R]
targets[R]

Public Class Methods

new(config_file: , targets: , force: ) click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 14
def initialize(config_file: , targets: , force: )
  @config_file = config_file
  @targets = targets.split(/\,/).map(&:strip) unless targets.nil?
  @force = force
end

Public Instance Methods

check_targets(targets, config_options) click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 48
def check_targets(targets, config_options)
  tmp_array = Array.new
  sync = config_options[:sync]

  targets.each do |t|
    sync.each do |h|
      tmp_array << h if h[:name] == t
    end
  end

  if tmp_array.empty?
    valid_targets = sync.map{|h| h[:name]}
    raise "Please specify at least one valid target\n Valid targets are #{valid_targets}"
  end

  config_options[:sync] = tmp_array
  config_options
end
cli_options() click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 36
def cli_options
  { cli: { targets: targets, force: force } }
end
config_options() click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 25
def config_options
  config_options = ConfigFile.new(default_options[:config_file]).run
  # Check that targets specified via commandline actually exist in config_file and update config_options[:sync] array
  config_options = check_targets(targets, config_options) unless targets.nil?
  config_options
end
default_options() click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 20
def default_options
  # default_options will search for config_file or take the path specified via cli
  DefaultOptions.new(config_file).run
end
env_options() click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 32
def env_options
  Env.new.run
end
final_options() click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 44
def final_options
  merge_options(default_options, config_options, env_options, cli_options)
end
merge_options(default_options, config_options, env_options, cli_options) click to toggle source
# File lib/sanctum/get_config/config_merge.rb, line 40
def merge_options(default_options, config_options, env_options, cli_options)
  default_options.deep_merge(config_options).deep_merge(env_options).deep_merge(cli_options)
end