Module: CapistranoSentinel::ApplicationHelper

Includes:
Logging
Included in:
RequestWorker, WebsocketClient
Defined in:
lib/capistrano_sentinel/helpers/application_helper.rb

Overview

class that holds the options that are configurable for this gem

Class Method Summary collapse

Methods included from Logging

error_filtered?, execute_with_rescue, find_worker_log, format_error, log_error, log_output_error, log_to_file, logger, logging_enabled?, print_to_log_file, rescue_error, setup_filename_logger, setup_logger_formatter, show_warning

Class Method Details

.get_question_details(data) ⇒ Object


36
37
38
39
# File 'lib/capistrano_sentinel/helpers/application_helper.rb', line 36

def get_question_details(data)
  matches = /(.*)\?*\s*\:*\s*(\([^)]*\))*/m.match(data).captures
  [matches[0], matches[1]]
end

.message_from_bundler?(message) ⇒ Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/capistrano_sentinel/helpers/application_helper.rb', line 32

def message_from_bundler?(message)
  message.present? && message.is_a?(Hash) && message['action'].present? && message['job_id'].present? && message['task'].present? && message['action'] == 'bundle_install'
end

.message_is_about_a_task?(message) ⇒ Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/capistrano_sentinel/helpers/application_helper.rb', line 28

def message_is_about_a_task?(message)
  message.present? && message.is_a?(Hash) && message['action'].present? && message['job_id'].present? && message['task'].present? && message['action'] == 'invoke'
end

.message_is_for_stdout?(message) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/capistrano_sentinel/helpers/application_helper.rb', line 24

def message_is_for_stdout?(message)
  message.present? && message.is_a?(Hash) && message['action'].present? && message['job_id'].present? && message['action'] == 'stdout'
end

.msg_for_stdin?(message) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/capistrano_sentinel/helpers/application_helper.rb', line 20

def msg_for_stdin?(message)
  message['action'] == 'stdin'
end

.parse_json(res) ⇒ Hash?

Method that is used to parse a string as JSON , if it fails will return nil

Parameters:

  • res (string)

    The string that will be parsed as JSON

Returns:

  • (Hash, nil)

    Returns Hash object if the json parse succeeds or nil otherwise

See Also:

  • JSON#parse

12
13
14
15
16
17
# File 'lib/capistrano_sentinel/helpers/application_helper.rb', line 12

def parse_json(res)
  return if res.blank?
  JSON.parse(res)
rescue JSON::ParserError
  nil
end