module CapistranoMulticonfigParallel::ApplicationHelper

class that holds the options that are configurable for this gem

Constants

DEFAULT_TEXT_LENGTH

Public Instance Methods

action_confirmed?(result) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 103
def action_confirmed?(result)
  result.present? && result.downcase == 'y'
end
fetch_parsed_string(string) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 116
def fetch_parsed_string(string)
  /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
  [regex_last_match(1), regex_last_match(2)]
end
fetch_remaining_arguments(args, remaining_args) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 121
def fetch_remaining_arguments(args, remaining_args)
  /((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
  args << regex_last_match(1).gsub(/\\(.)/, '\1')
  regex_last_match(2)
end
find_remaining_args(name, remaining_args) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 127
def find_remaining_args(name, remaining_args)
  args = []
  loop do
    remaining_args = fetch_remaining_arguments(args, remaining_args)
    break if remaining_args.blank?
  end
  [name, args]
end
get_question_details(data) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 73
def get_question_details(data)
  matches = /(.*)\?*\s*\:*\s*(\([^)]*\))*/m.match(data).captures
  [matches[0], matches[1]]
end
internal_wrap_string(string, options = {}) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 83
def internal_wrap_string(string, options = {})
  options.stringify_keys!
  string.scan(/.{#{options.fetch('length', CapistranoMulticonfigParallel::ApplicationHelper::DEFAULT_TEXT_LENGTH)}}|.+/).map(&:strip)
end
message_from_bundler?(message) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 69
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) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 65
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) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 61
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) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 57
def msg_for_stdin?(message)
  message['action'] == 'stdin'
end
parse_json(res) click to toggle source

Method that is used to parse a string as JSON , if it fails will return nil @see JSON#parse @param [string] res The string that will be parsed as JSON @return [Hash, nil] Returns Hash object if the json parse succeeds or nil otherwise

# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 50
def parse_json(res)
  return if res.blank?
  JSON.parse(res)
rescue JSON::ParserError
  nil
end
percent_of(index, total) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 99
def percent_of(index, total)
  index.to_f / total.to_f * 100.0
end
regex_last_match(number) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 107
def regex_last_match(number)
  Regexp.last_match(number)
end
setup_command_line_standard(*args) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 78
def setup_command_line_standard(*args)
  options = args.extract_options!
  [args.select(&:present?), options]
end
truncate(string, truncate_at, options = {}) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 32
def truncate(string, truncate_at, options = {})
  return string.dup unless string.length > truncate_at

  options[:omission] ||= '...'
  length_with_room_for_omission = truncate_at - options[:omission].length
  stop =        if options[:separator]
    string.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
  else
    length_with_room_for_omission
  end

  "#{string[0...stop]}#{options[:omission]}"
end
wrap_coloured_string(string, options = {}) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 92
def wrap_coloured_string(string, options = {})
  new_array = internal_wrap_string(string, options).collect do |str|
    str.colorize(options["color"].to_s.to_sym)
  end
  new_array.join(options.fetch('character', $INPUT_RECORD_SEPARATOR))
end
wrap_string(string, options = {}) click to toggle source
# File lib/capistrano_multiconfig_parallel/helpers/application_helper.rb, line 88
def wrap_string(string, options = {})
  internal_wrap_string(string, options).join(options.fetch('character', $INPUT_RECORD_SEPARATOR))
end