Module: CapistranoMulticonfigParallel::CoreHelper
- Included in:
- ApplicationHelper
- Defined in:
- lib/capistrano_multiconfig_parallel/helpers/core_helper.rb
Overview
class that holds the options that are configurable for this gem
Class Method Summary collapse
- .app_configuration ⇒ Object
- .app_debug_enabled? ⇒ Boolean
- .app_logger ⇒ Object
- .ask_confirm(message, default) ⇒ Object
- .check_terminal_tty ⇒ Object
- .debug_websocket? ⇒ Boolean
- .execute_with_rescue(output = nil) ⇒ Object
- .find_config_type(type) ⇒ Object
- .find_loaded_gem(name) ⇒ Object
- .find_worker_log(job_id) ⇒ Object
- .force_confirmation(&block) ⇒ Object
- .format_error(error) ⇒ Object
- .log_error(error) ⇒ Object
- .log_to_file(message, job_id = nil) ⇒ Object
- .rescue_error(error, output = nil) ⇒ Object
- .rescue_interrupt ⇒ Object
- .show_warning(message) ⇒ Object
- .websocket_config ⇒ Object
- .websocket_server_config ⇒ Object
Class Method Details
.app_configuration ⇒ Object
18 19 20 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 18 def app_configuration CapistranoMulticonfigParallel.configuration end |
.app_debug_enabled? ⇒ Boolean
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 10 def app_debug_enabled? app_configuration.multi_debug.to_s.downcase == 'true' end |
.app_logger ⇒ Object
22 23 24 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 22 def app_logger CapistranoMulticonfigParallel.logger end |
.ask_confirm(message, default) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 35 def ask_confirm(, default) force_confirmation do Ask.input , default: default end rescue return nil end |
.check_terminal_tty ⇒ Object
26 27 28 29 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 26 def check_terminal_tty $stdin.sync = true if $stdin.isatty $stdout.sync = true if $stdout.isatty end |
.debug_websocket? ⇒ Boolean
80 81 82 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 80 def debug_websocket? websocket_server_config['enable_debug'].to_s == 'true' end |
.execute_with_rescue(output = nil) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 92 def execute_with_rescue(output = nil) yield if block_given? rescue Interrupt rescue_interrupt rescue => error rescue_error(error, output) end |
.find_config_type(type) ⇒ Object
6 7 8 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 6 def find_config_type(type) ['boolean'].include?(type.to_s) ? type.to_s.delete(':').to_sym : type.to_s.constantize end |
.find_loaded_gem(name) ⇒ Object
31 32 33 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 31 def find_loaded_gem(name) Gem.loaded_specs.values.find { |repo| repo.name == name } end |
.find_worker_log(job_id) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 67 def find_worker_log(job_id) return if job_id.blank? FileUtils.mkdir_p(log_directory) unless File.directory?(log_directory) filename = File.join(log_directory, "worker_#{job_id}.log") worker_log = ::Logger.new(filename) worker_log.level = ::Logger::Severity::DEBUG worker_log.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime('%Y-%m-%d %H:%M:%S') "[#{date_format}] #{severity} (#{progname}): #{msg}\n" end worker_log end |
.force_confirmation(&block) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 43 def force_confirmation(&block) `stty -raw echo` check_terminal_tty result = block.call $stdout.flush `stty -raw echo` result end |
.format_error(error) ⇒ Object
56 57 58 59 60 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 56 def format_error(error) JSON.pretty_generate(class_name: error.class, message: error.respond_to?(:message) ? error. : error.inspect, backtrace: error.respond_to?(:backtrace) ? error.backtrace.join("\n\n") : '') end |
.log_error(error) ⇒ Object
52 53 54 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 52 def log_error(error) log_to_file(format_error(error)) end |
.log_to_file(message, job_id = nil) ⇒ Object
62 63 64 65 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 62 def log_to_file(, job_id = nil) worker_log = job_id.present? ? find_worker_log(job_id) : app_logger worker_log.debug() if worker_log.present? && app_debug_enabled? end |
.rescue_error(error, output = nil) ⇒ Object
100 101 102 103 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 100 def rescue_error(error, output = nil) output.blank? ? log_error(error) : puts(format_error(error)) exit(1) end |
.rescue_interrupt ⇒ Object
105 106 107 108 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 105 def rescue_interrupt `stty icanon echo` puts "\n Command was cancelled due to an Interrupt error." end |
.show_warning(message) ⇒ Object
14 15 16 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 14 def show_warning() warn if app_debug_enabled? end |
.websocket_config ⇒ Object
88 89 90 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 88 def websocket_config websocket_server_config.merge('enable_debug' => debug_websocket?) end |
.websocket_server_config ⇒ Object
84 85 86 |
# File 'lib/capistrano_multiconfig_parallel/helpers/core_helper.rb', line 84 def websocket_server_config app_configuration.fetch(:websocket_server, {}).stringify_keys end |