class Forcer::ActionOptionsService

Public Class Methods

load_config(old_options = {}) click to toggle source

attempts to load configuration files from directory ‘forcer_config’ directory can include ‘configuration.yml’, ‘exclude_components.yml’, ‘exclude_xml_nodes.yml’ if directory not found tries to load only configuration.yml from local directory

# File lib/utilities/action_options_service.rb, line 9
def self.load_config(old_options = {})
  options = clone_options(old_options)

  verify_config_folder(options)

  load_login_info(options)

  add_exclude_paths(options)

  return options
end

Private Class Methods

add_exclude_paths(options = {}) click to toggle source

add absolute paths to exclude_… files from focer_config directory

# File lib/utilities/action_options_service.rb, line 85
def add_exclude_paths(options = {})
  return if (options[:configs].nil?)

  exclude_components_path = File.join(options[:configs], "/exclude_components.yml")
  options[:exclude_components] = exclude_components_path if File.exists?(exclude_components_path)

  exclude_xml_path = File.join(options[:configs], "/exclude_xml_nodes.yml")
  options[:exclude_xml] = exclude_xml_path if File.exists?(exclude_xml_path)
end
clone_options(old_options = {}) click to toggle source

Thor restricts options modification. Therefore have to clone hash “options”

# File lib/utilities/action_options_service.rb, line 26
def clone_options(old_options = {})
  options = {}
  old_options.each do |k, v|
    options.store(k.to_sym, v)
  end

  return options
end
get_config_file_path(options = {}) click to toggle source

defines which configuration.yml to use for authentication. Preference is to save configuration.yml in folder ‘forcer_config’ which itself should be placed in project git repo directory

# File lib/utilities/action_options_service.rb, line 69
def get_config_file_path(options = {})
  config_file_path = File.join(options[:configs], "/configuration.yml")

  if File.exists?(config_file_path)
    p "CONFIGURATION.YML with org details FOUND in CONFIG FOLDER"
    options[:login_info_path] = config_file_path
  else
    p "loading CONFIGURATION.YML from CURRENT DIRECTORY"
    config_file_path = File.join(Dir.pwd, "/configuration.yml")
  end

  return config_file_path
end
load_login_info(options = {}) click to toggle source

attempts to read salesforce org information from forcer_config/configuration.yml if forcer_config/configuration.yml not found, then try configuration.yml in current directory

# File lib/utilities/action_options_service.rb, line 48
def load_login_info(options = {})

  config_file_path = get_config_file_path(options)

  # don't raise exception and let user enter all necessary information
  return options unless File.exists?(config_file_path)

  destination_org = options[:dest]
  configuration = YAML.load_file(config_file_path).to_hash

  return options if configuration[destination_org].nil?

  configuration[destination_org].each do |key, value|
    options.store(key.to_sym, value.to_s)  unless value.to_s.empty?
  end

  options[:host] = "https://#{options[:host]}" unless options[:host].include?("http")
end
verify_config_folder(options = {}) click to toggle source
# File lib/utilities/action_options_service.rb, line 35
def verify_config_folder(options = {})
  if options[:configs].nil? || !(Dir.exists?(File.expand_path(options[:configs], __FILE__)))
    p "config folder not specified or not found"
    options[:configs] = Dir.pwd + "/forcer_config"
    p "config folder in CURRENT DIRECTORY ? => #{Dir.exists?(options[:configs])}"
  else
    p "specified config folder FOUND"
    options[:configs] = File.expand_path(options[:configs], __FILE__)
  end
end