lib/pdk/util/ruby_version.rb in pdk-akerl-1.9.1.1 vs lib/pdk/util/ruby_version.rb in pdk-akerl-1.14.0.1
- old
+ new
@@ -1,15 +1,17 @@
-require 'pdk/util'
+require 'forwardable'
module PDK
module Util
class RubyVersion
class << self
extend Forwardable
def_delegators :instance, :gem_path, :gem_paths_raw, :gem_home, :available_puppet_versions, :bin_path
+ # TODO: resolve this
+ # rubocop:disable Lint/DuplicateMethods
attr_reader :instance
def instance(version = nil)
use(version) unless version.nil?
@@ -19,10 +21,11 @@
hash[key] = new(key)
end
end
@instance[active_ruby_version]
end
+ # rubocop:enable Lint/DuplicateMethods
def active_ruby_version
@active_ruby_version || default_ruby_version
end
@@ -35,31 +38,45 @@
}
end
end
def scan_for_packaged_rubies
+ require 'pdk/util'
+
ruby_basedir = File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', '*')
Dir[ruby_basedir].sort.map { |ruby_dir|
version = File.basename(ruby_dir)
[version, version.split('.').take(2).concat(['0']).join('.')]
}.reverse.to_h
end
def default_ruby_version
- # For now, the packaged versions will be using default of 2.4.5
- # FIXME: make this dynamic
- return '2.4.5' if PDK::Util.package_install?
+ require 'pdk/util'
+ require 'pdk/util/puppet_version'
- # TODO: may not be a safe assumption that highest available version should be default
- latest_ruby_version
+ @default_ruby_version ||= if PDK::Util.package_install?
+ # Default to the ruby that supports the latest puppet gem. If you wish to default to a
+ # specific Puppet Gem version use the following example;
+ #
+ # PDK::Util::PuppetVersion.find_gem_for('5.5.10')[:ruby_version]
+ #
+ PDK::Util::PuppetVersion.latest_available[:ruby_version]
+ else
+ # TODO: may not be a safe assumption that highest available version should be default
+ # WARNING Do NOT use PDK::Util::PuppetVersion.*** methods as it can recurse into this
+ # method and cause Stack Level Too Deep errors.
+ latest_ruby_version
+ end
end
def latest_ruby_version
versions.keys.sort { |a, b| Gem::Version.new(b) <=> Gem::Version.new(a) }.first
end
def versions
+ require 'pdk/util'
+
@versions ||= if PDK::Util.package_install?
scan_for_packaged_rubies
else
{ RbConfig::CONFIG['RUBY_PROGRAM_VERSION'] => RbConfig::CONFIG['ruby_version'] }
end
@@ -71,18 +88,22 @@
def initialize(ruby_version = nil)
@ruby_version = ruby_version || default_ruby_version
end
def bin_path
+ require 'pdk/util'
+
if PDK::Util.package_install?
File.join(PDK::Util.pdk_package_basedir, 'private', 'ruby', ruby_version, 'bin')
else
RbConfig::CONFIG['bindir']
end
end
def gem_paths_raw
+ require 'pdk/util'
+
if PDK::Util.package_install?
# Subprocesses use their own set of gems which are managed by pdk or
# installed with the package. We also include the separate gem path
# where our packaged multi-puppet installations live.
[
@@ -102,9 +123,11 @@
def gem_path
gem_paths_raw.join(File::PATH_SEPARATOR)
end
def gem_home
+ require 'pdk/util'
+
# `bundle install --path` ignores all "system" installed gems and
# causes unnecessary package installs. `bundle install` (without
# --path) installs into GEM_HOME, which by default is non-user
# writeable.
# To still use the pre-installed packages, but allow folks to install