Module: CapistranoMulticonfigParallel::Configuration

Includes:
CoreHelper, InternalHelper, ParseHelper
Included in:
CapistranoMulticonfigParallel
Defined in:
lib/capistrano_multiconfig_parallel/helpers/configuration.rb

Overview

class that holds the options that are configurable for this gem

Instance Method Summary collapse

Methods included from ParseHelper

check_hash_set, check_numeric, strip_characters_from_string, value_is_array?, verify_array_of_strings, verify_empty_options, warn_array_without_strings

Methods included from InternalHelper

arg_is_in_default_config?, check_file, create_log_file, custom_commands, default_config_keys, default_internal_config, default_internal_configuration_params, detect_root, enable_main_log_file, fail_capfile_not_found, fetch_default_internal_config, find_config_type, find_env_multi_cap_root, find_file_by_names, find_file_in_directory, get_current_gem_name, internal_config_directory, internal_config_file, log_directory, main_log_file, multi_level_prop, pathname_is_root?, pwd_directory, pwd_parent_dir, root, setup_default_configuration_types, sliced_default_config, try_detect_file, try_detect_file_in_dir

Methods included from CoreHelper

app_debug_enabled?, ask_confirm, ask_stdout_confirmation, check_terminal_tty, debug_websocket?, development_debug?, error_filtered?, execute_with_rescue, find_worker_log, force_confirmation, format_error, log_error, log_output_error, log_to_file, multi_fetch_argv, print_to_log_file, rescue_error, rescue_interrupt, setup_filename_logger, setup_logger_formatter, show_warning, terminal_actor, terminal_errors?, websocket_config, websocket_server_config

Instance Method Details

#check_array_of_hash(value, props) ⇒ Object



62
63
64
65
66
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 62

def check_array_of_hash(value, props)
  value.find do|hash|
    check_hash_set(hash, props)
  end
end

#check_array_props(props) ⇒ Object



87
88
89
90
91
92
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 87

def check_array_props(props)
  props.each do |prop|
    value = get_prop_config(prop)
    @check_config[prop] = value if value_is_array?(value) && verify_array_of_strings(value)
  end
end

#check_boolean(prop) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 68

def check_boolean(prop)
  value = get_prop_config(prop)
  if %w(true false).include?(value.to_s.downcase)
    true
  else
    raise ArgumentError, "the property `#{prop}` must be boolean"
  end
end

#check_boolean_props(props) ⇒ Object



81
82
83
84
85
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 81

def check_boolean_props(props)
  props.each do |prop|
    @check_config[prop] = get_prop_config(prop) if check_boolean(prop)
  end
end

#check_configuration(config) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 116

def check_configuration(config)
  @check_config = config.stringify_keys
  check_boolean_props(%w(multi_debug multi_secvential websocket_server.enable_debug terminal.clear_screen check_app_bundler_dependencies))
  check_string_props(%w(websocket_server.adapter))
  check_array_props(%w(task_confirmations development_stages apply_stage_confirmation))
  check_directories(%w(log_dir config_dir))
  verify_application_dependencies(@check_config['application_dependencies'], %w(app priority dependencies))
end

#check_directories(props) ⇒ Object



109
110
111
112
113
114
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 109

def check_directories(props)
  props.each do |prop|
    value = get_prop_config(prop)
    @check_config[prop] = value if value.present? && File.directory?(value)
  end
end

#check_string_props(props) ⇒ Object



94
95
96
97
98
99
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 94

def check_string_props(props)
  props.each do |prop|
    value = get_prop_config(prop)
    @check_config[prop] = value if value.is_a?(String)
  end
end

#configuration_valid?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 77

def configuration_valid?
  configuration
end

#fetch_configurationObject



11
12
13
14
15
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 11

def fetch_configuration
  @fetched_config = Configliere::Param.new
  setup_default_config
  setup_configuration
end

#get_prop_config(prop, config = @check_config) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 101

def get_prop_config(prop, config = @check_config)
  if prop.include?('.')
    multi_level_prop(config, prop)
  else
    config[prop]
  end
end

#read_config_fileObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 39

def read_config_file
  return if CapistranoMulticonfigParallel.original_args.present? && CapistranoMulticonfigParallel.original_args.include?('--help')
  user = Etc.getlogin
  config_file_path = File.join(Dir.home(user), "multi_cap.yml")
  if File.exists?(config_file_path)
    @fetched_config.config_dir  = File.dirname(config_file_path)
  else
    @fetched_config.config_dir = @fetched_config.config_dir.present? ? File.expand_path(@fetched_config.config_dir) : try_detect_file('multi_cap.yml')
    config_file_path = @fetched_config.config_dir.present? ? File.join(@fetched_config.config_dir, 'multi_cap.yml') : nil
  end
  config_file = File.expand_path(config_file_path || File.join(detect_root.to_s, 'config', 'multi_cap.yml'))
  @fetched_config.config_dir = File.dirname(config_file)
  @fetched_config.log_dir = config_file_path.present? ? File.dirname(config_file) : File.dirname(File.dirname(config_file))
  @fetched_config.read config_file if File.file?(config_file)
end

#setup_configurationObject



23
24
25
26
27
28
29
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 23

def setup_configuration
  @fetched_config.use :commandline
  @fetched_config.process_argv!
  read_config_file
  @fetched_config.use :config_block
  validate_configuration
end

#setup_default_configObject



17
18
19
20
21
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 17

def setup_default_config
  default_internal_config.each do |array_param|
    @fetched_config.define array_param[0], array_param[1].symbolize_keys
  end
end

#validate_configurationObject



31
32
33
34
35
36
37
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 31

def validate_configuration
  @fetched_config.finally do |config|
    check_configuration(config)
  end
  @fetched_config.resolve!
  @fetched_config
end

#verify_application_dependencies(value, props) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/capistrano_multiconfig_parallel/helpers/configuration.rb', line 55

def verify_application_dependencies(value, props)
  return unless value.is_a?(Array)
  value.reject { |val| val.blank? || !val.is_a?(Hash) }
  wrong = check_array_of_hash(value, props.map(&:to_sym))
  raise ArgumentError, "invalid configuration for #{wrong.inspect}" if wrong.present?
end