Module: CapistranoMulticonfigParallel::ParseHelper

Included in:
ApplicationHelper, Configuration
Defined in:
lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb

Overview

module used for parsing numbers, strings , arrays and hashes

Class Method Summary collapse

Class Method Details

.check_hash_set(hash, props) ⇒ Object



29
30
31
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 29

def check_hash_set(hash, props)
  !Set.new(props).subset?(hash.keys.to_set) || hash.values.find(&:blank?).present?
end

.check_numeric(num) ⇒ Object



6
7
8
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 6

def check_numeric(num)
  /^[0-9]+/.match(num.to_s)
end

.strip_characters_from_string(value) ⇒ Object



37
38
39
40
41
42
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 37

def strip_characters_from_string(value)
  return '' if value.blank?
  value = value.delete("\r\n").delete("\n")
  value = value.gsub(/\s+/, ' ').strip
  value
end

.value_is_array?(value) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 33

def value_is_array?(value)
  value.present? && value.is_a?(Array)
end

.verify_array_of_strings(value) ⇒ Object



20
21
22
23
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 20

def verify_array_of_strings(value)
  value = verify_empty_options(value)
  value.find { |row| !row.is_a?(String) }.present? ? warn_array_without_strings(value) : true
end

.verify_empty_options(options) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 10

def verify_empty_options(options)
  if options.is_a?(Hash)
    options.reject { |_key, value| value.blank? }
  elsif options.is_a?(Array)
    options.reject(&:blank?)
  else
    options
  end
end

.warn_array_without_strings(value) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
# File 'lib/capistrano_multiconfig_parallel/helpers/parse_helper.rb', line 25

def warn_array_without_strings(value)
  raise ArgumentError, "the array #{value} must contain only task names"
end