Module: Appraisal::Utils

Defined in:
lib/appraisal/utils.rb

Overview

Contains methods for various operations

Class Method Summary collapse

Class Method Details

.bundler_versionObject



66
67
68
# File 'lib/appraisal/utils.rb', line 66

def bundler_version
  Gem::Specification.detect { |spec| spec.name == "bundler" }.version.to_s
end

.format_arguments(arguments) ⇒ Object



47
48
49
50
51
# File 'lib/appraisal/utils.rb', line 47

def format_arguments(arguments)
  return if arguments.empty?

  arguments.map { |object| format_string(object, false) }.join(", ")
end

.format_hash_value(key, value) ⇒ Object

Appraisal needs to print Gemfiles in the oldest Ruby syntax that is supported by Appraisal.
This means formatting Hashes as Rockets, until support for Ruby 1.8 is dropped.
Regardless of what Ruby is used to generate appraisals,
generated appraisals may need to run on a different Ruby version.
Generated appraisals should use a syntax compliant with the oldest supported Ruby version.



40
41
42
43
44
45
# File 'lib/appraisal/utils.rb', line 40

def format_hash_value(key, value)
  key = format_string(key, true)
  value = format_string(value, true)

  "#{key} => #{value}"
end

.format_string(object, enclosing_object = false) ⇒ Object

Appraisal needs to print Gemfiles in the oldest Ruby syntax that is supported by Appraisal.
Otherwise, a project would not be able to use Appraisal to test compatibility
with older versions of Ruby, which is a core use case for Appraisal.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appraisal/utils.rb', line 18

def format_string(object, enclosing_object = false)
  case object
  when Hash
    items = object.map do |key, value|
      format_hash_value(key, value)
    end

    if enclosing_object
      "{ #{items.join(", ")} }"
    else
      items.join(", ")
    end
  else
    object.inspect
  end
end

.join_parts(parts) ⇒ Object



53
54
55
# File 'lib/appraisal/utils.rb', line 53

def join_parts(parts)
  parts.reject(&:nil?).reject(&:empty?).join("\n\n").rstrip
end

.prefix_path(path) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/appraisal/utils.rb', line 57

def prefix_path(path)
  if path !~ /^(?:\/|\S:)/ && path !~ /^\S+:\/\// && path !~ /^\S+@\S+:/
    cleaned_path = path.gsub(/(^|\/)\.(?:\/|$)/, "\\1")
    File.join("..", cleaned_path)
  else
    path
  end
end

.support_git_local_installation?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/appraisal/utils.rb', line 11

def support_git_local_installation?
  Gem::Version.create(Bundler::VERSION) > Gem::Version.create("2.4.22")
end

.support_parallel_installation?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/appraisal/utils.rb', line 7

def support_parallel_installation?
  Gem::Version.create(Bundler::VERSION) >= Gem::Version.create("1.4.0.pre.1")
end