Module: Appraisal::Utils
- Defined in:
- lib/appraisal/utils.rb
Overview
Contains methods for various operations
Class Method Summary collapse
- .bundler_version ⇒ Object
- .format_arguments(arguments) ⇒ Object
-
.format_hash_value(key, value) ⇒ Object
Appraisal needs to print Gemfiles in the oldest Ruby syntax that is supported by Appraisal.
-
.format_string(object, enclosing_object = false) ⇒ Object
Appraisal needs to print Gemfiles in the oldest Ruby syntax that is supported by Appraisal.
- .join_parts(parts) ⇒ Object
- .prefix_path(path) ⇒ Object
- .support_bundle_update_all? ⇒ Boolean
- .support_git_local_installation? ⇒ Boolean
- .support_parallel_installation? ⇒ Boolean
Class Method Details
.bundler_version ⇒ Object
70 71 72 73 74 75 |
# File 'lib/appraisal/utils.rb', line 70 def bundler_version spec = Gem::Specification.detect { |s| s.name == "bundler" } return "2.4.22" unless spec # Fallback for very old systems spec.version.to_s end |
.format_arguments(arguments) ⇒ Object
51 52 53 54 55 |
# File 'lib/appraisal/utils.rb', line 51 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.
44 45 46 47 48 49 |
# File 'lib/appraisal/utils.rb', line 44 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/appraisal/utils.rb', line 22 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
57 58 59 |
# File 'lib/appraisal/utils.rb', line 57 def join_parts(parts) parts.reject(&:nil?).reject(&:empty?).join("\n\n").rstrip end |
.prefix_path(path) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/appraisal/utils.rb', line 61 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_bundle_update_all? ⇒ Boolean
15 16 17 |
# File 'lib/appraisal/utils.rb', line 15 def support_bundle_update_all? Gem::Version.create(Bundler::VERSION) >= Gem::Version.create("1.16.5") end |
.support_git_local_installation? ⇒ 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
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 |