Class: CapistranoMulticonfigParallel::JobCommand
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::JobCommand
show all
- Includes:
- ApplicationHelper, FileUtils
- Defined in:
- lib/capistrano_multiconfig_parallel/classes/job_command.rb
Overview
class used to find application dependencies
Instance Attribute Summary collapse
Instance Method Summary
collapse
action_confirmed?, fetch_parsed_string, fetch_remaining_arguments, find_remaining_args, get_question_details, message_from_bundler?, message_is_about_a_task?, message_is_for_stdout?, msg_for_stdin?, parse_task_string, percent_of, regex_last_match, setup_command_line_standard, wrap_string
env_key_format, env_prefix, filtered_env_keys_format, setup_flags_for_job, trace_flag
Methods included from GemHelper
fetch_gem_version, find_loaded_gem, find_loaded_gem_property, format_gem_version, get_parsed_version, verify_gem_version
app_names_from_stages, check_stage_path, checks_paths, fetch_stages_app, fetch_stages_from_file, fetch_stages_paths, independent_deploy?, multi_apps?, sorted_paths, stages, stages_paths, stages_root
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 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
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_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
Constructor Details
Returns a new instance of JobCommand.
12
13
14
15
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 12
def initialize(job)
@job = job
@legacy_capistrano = legacy_capistrano? ? true : false
end
|
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 9
def job
@job
end
|
#job_capistrano_version ⇒ Object
Returns the value of attribute job_capistrano_version.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 9
def job_capistrano_version
@job_capistrano_version
end
|
#legacy_capistrano ⇒ Object
Returns the value of attribute legacy_capistrano.
9
10
11
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 9
def legacy_capistrano
@legacy_capistrano
end
|
Instance Method Details
#bundle_gemfile_env ⇒ Object
46
47
48
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 46
def bundle_gemfile_env
"BUNDLE_GEMFILE=#{job_gemfile}"
end
|
#capistrano_action ⇒ Object
59
60
61
62
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 59
def capistrano_action
argv = task_arguments.present? ? "[#{task_arguments}]" : ''
"#{action}#{argv}"
end
|
#command_prefix ⇒ Object
99
100
101
102
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 99
def command_prefix
bundle_install = path.present? ? "&& #{bundle_gemfile_env} bundle install" : ''
"cd #{job_path} #{bundle_install}"
end
|
#env_option_filtered?(key, filtered_keys_array = []) ⇒ Boolean
64
65
66
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 64
def env_option_filtered?(key, filtered_keys_array = [])
filtered_env_keys.include?(env_key_format(key)) || filtered_keys_array.include?(key.to_s)
end
|
#execute_standard_deploy(action = nil) ⇒ Object
114
115
116
117
118
119
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 114
def execute_standard_deploy(action = nil)
run_shell_command(to_s)
rescue => ex
rescue_error(ex, 'stderr')
execute_standard_deploy('deploy:rollback') if action.blank? && @name == 'deploy'
end
|
#filtered_env_keys ⇒ Object
42
43
44
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 42
def filtered_env_keys
%w(STAGES ACTION)
end
|
#gem_specs ⇒ Object
25
26
27
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 25
def gem_specs
@specs = lockfile_parser.specs
end
|
#gitflow_enabled? ⇒ Boolean
50
51
52
53
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 50
def gitflow_enabled?
gitflow_version = job_gem_version("capistrano-gitflow")
gitflow_version.present? ? true : false
end
|
#job_gem_version(gem_name) ⇒ Object
37
38
39
40
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 37
def job_gem_version(gem_name)
gem_spec = gem_specs.find {|spec| spec.name == gem_name}
gem_spec.present? ? gem_spec.version.to_s : nil
end
|
#job_gemfile ⇒ Object
29
30
31
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 29
def job_gemfile
File.join(job_path, 'Gemfile')
end
|
#job_gemfile_lock ⇒ Object
33
34
35
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 33
def job_gemfile_lock
File.join(job_path, 'Gemfile.lock')
end
|
#job_path ⇒ Object
95
96
97
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 95
def job_path
path || detect_root
end
|
#job_stage ⇒ Object
55
56
57
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 55
def job_stage
multi_apps?(job_path) && app.present? ? "#{app}:#{stage}" : "#{stage}"
end
|
#legacy_capistrano? ⇒ Boolean
91
92
93
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 91
def legacy_capistrano?
verify_gem_version(job_capistrano_version, '3.0', operator: '<')
end
|
#lockfile_parser ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 17
def lockfile_parser
if File.exists?(job_gemfile_lock)
@lockfile_parser ||= Bundler::LockfileParser.new(Bundler.read_file("#{job_gemfile_lock}"))
else
raise RuntimeError, "please install the gems separately for this application #{job_path} and re-try again!"
end
end
|
#setup_command_line(*args) ⇒ Object
82
83
84
85
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 82
def setup_command_line(*args)
new_arguments, options = setup_command_line_standard(*args)
setup_env_options(options).concat(new_arguments)
end
|
#setup_env_options(options = {}) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 68
def setup_env_options(options = {})
array_options = []
filtered_keys = options.delete(:filtered_keys) || []
env_options.each do |key, value|
array_options << "#{env_prefix(key, @legacy_capistrano)} #{env_key_format(key, @legacy_capistrano)}=#{value}" if value.present? && !env_option_filtered?(key, filtered_keys)
end
setup_remaining_flags(array_options, options)
end
|
#setup_remaining_flags(array_options, options) ⇒ Object
77
78
79
80
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 77
def setup_remaining_flags(array_options, options)
array_options << trace_flag(@legacy_capistrano) if app_debug_enabled?
array_options.concat(setup_flags_for_job(options))
end
|
#to_json ⇒ Object
110
111
112
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 110
def to_json
{ command: to_s }
end
|
#to_s ⇒ Object
104
105
106
107
108
|
# File 'lib/capistrano_multiconfig_parallel/classes/job_command.rb', line 104
def to_s
config_flags = CapistranoMulticonfigParallel.configuration_flags
environment_options = setup_command_line(config_flags).join(' ')
"#{command_prefix} && #{bundle_gemfile_env} bundle exec multi_cap #{job_stage} #{capistrano_action} #{environment_options}"
end
|